Wednesday, March 12, 2014

Get-Help examples in Powershell

get-help - This displays information and examples about the powershell cmdlets

PS C:\> get-help             -- Displays help about get-help

TOPIC
    Windows PowerShell Help System


PS C:\> get-help get-help -Online        -- Displays online versin of get-help command, it displays help in browser

PS C:\> \get-help get-process               -- Displays help about the get-process cmdlet

PS C:\> \get-help get-process -full       -- Full switch helps to display complete information along with switches, descirptions and examples.


PS C:\> \get-help get-process -examples -- Displays only examples of the get-process cmdlet

PS C:\> get-help get*                               -- Displays all cmdlets starts with get

PS C:\> get-help about_split | more         -- Displays information about the split command, usage and examples

TOPIC
    about_Split
SHORT DESCRIPTION
    Explains how to use the Split operator to split one or more strings into
    substrings.

PS C:\> get-help dir -examples                -- Displays examples of the dir commnad

 

How to identify Powershell Version

Below are the various ways to identify the powershell version

Start - Run - Powershell

PS > get-host

<output>
Name             : ConsoleHost
Version          : 3.0
'
'
PS > $psversiontable

Name                           Value
----                           -----
WSManStackVersion              3.0

PS C:\> $host.version
Major  Minor  Build  Revision
-----  -----  -----  --------
3      0      -1     -1

PS C:\> $psversiontable.psversion
Major  Minor  Build  Revision
-----  -----  -----  --------
3      0      -1     -1

PS C:\> host

Name             : ConsoleHost
Version          : 3.0
PS C:\> get-host | select-object Version
Version
-------
3.0

Tuesday, March 11, 2014

How to delete duplicate records in SQL Server


To delete any duplicate records in SQL Server

create table t1 (col1 int, col2 int)

insert into t1 values ( 1, 70)
insert into t1 values ( 1, 70)
insert into t1 values ( 1, 71)
insert into t1 values ( 1, 72)
insert into t1 values ( 1, 72)
insert into t1 values ( 1, 73)
insert into t1 values ( 1, 74)
insert into t1 values ( 1, 75)

select * from t1

with t1dups (col1, coldups)
AS (
select col2, ROW_NUMBER() Over (Partition by col1, col2 order by col2) as dups from t1 )
delete from t1dups where coldups > 1

select * from t1