Tuesday, March 9, 2010

Windows 7 PowerShell

Comparison of cmdlets with similar commands

The following table contains a selection of the cmdlets that ship with PowerShell noting the most similar commands in other well known command line interpreters.

Windows PowerShell

(Cmdlet)

Windows PowerShell

(Alias)

cmd.exe / COMMAND.COM

(MS-DOS, Windows, OS/2, etc.)

Bash

(Unix, BSD, Linux, Mac OS X etc.)

Description

Get-Location

gl, pwd

cd

pwd

Display the current directory/present working directory.

Set-Location

sl, cd, chdir

cd, chdir

cd

Change the current directory

Clear-Host

cls, clear

cls

clear

Clear the screen[35]

Copy-Item

cpi, copy, cp

copy

cp

Copy one or several files / a whole directory tree

Get-Help

help, man

help

man

Help on commands

Remove-Item

ri, del, erase, rmdir, rd, rm

del, erase, rmdir, rd

rm, rmdir

Delete a file / a directory

Rename-Item

rni, ren

ren, rename

mv

Rename a file / a directory

Move-Item

mi, move, mv

move

mv

Move a file / a directory to a new location

Get-ChildItem

gci, dir, ls

dir

ls

List all files / directories in the (current) directory

Write-Output

echo, write

echo

echo

Print strings, variables etc. to standard output

Pop-Location

popd

popd

popd

Change the current directory to the directory most recently pushed onto the stack

Push-Location

pushd

pushd

pushd

Push the current directory onto the stack

Set-Variable

sv, set

set

set

Set the value of a variable / create a variable

Get-Content

gc, type, cat

type

cat

Get the content of a file

Select-String

  

find, findstr

grep

Print lines matching a pattern

Get-Process

gps, ps

tlist,[36] tasklist[37]

ps

List all currently running processes

Stop-Process

spps, kill

kill,[36] taskkill[37]

kill

Stop a running process

Tee-Object

tee

n/a

tee

Pipe input to a file or variable, then pass the input along the pipeline

Examples

Examples are provided first using the long-form canonical syntax and then using more terse UNIX-like and DOS-like aliases that are set up in the default configuration.

  • Stop all processes that begin with the letter "p":

PS> get-process p* | stop-process

PS> ps p* | kill

  • Find the processes that use more than 1000 MB of memory and kill them:

PS> get-process | where-object { $_.WS -gt 1000MB } | stop-process

PS> ps | ? { $_.WS -gt 1000MB } | kill

  • Calculate the number of bytes in the files in a directory:

PS> get-childitem | measure-object -property length -sum

PS> ls | measure length -s

PS> dir | measure length -s

  • Determine whether a specific process is no longer running:

PS> $processToWatch = get-process notepad
PS> $processToWatch.WaitForExit()

PS> (ps notepad).WaitForExit()

  • Change the case of a string from lower to upper:

PS> "hello, world!".ToUpper()

  • Insert the string "ABC" after the first character in the word "string" to have the result "sABCtring":

PS> "string".Insert(1, "ABC")

  • Download a specific RSS feed and show the titles of the 8 most recent entries:

PS> $rssUrl = "http://blogs.msdn.com/powershell/rss.aspx"
PS> $blog = [xml](new-object System.Net.WebClient).DownloadString($rssUrl)
PS> $blog.rss.channel.item | select title -first 8

$x=new-object xml;$x.load("http://blogs.msdn.com/powershell/rss.aspx");$x.rss.channel.item|select title -f 8

  • Sets $UserProfile to the value of the UserProfile environment variable

PS> $UserProfile = $env:UserProfile

  • Cast a .Net Namespace, and call a method exposed by the cast

PS> [System.Windows.Forms.MessageBox]::Show("Hello, World!")

  • Run a command line executable, with arguments.

PS> [Array]$arguments = "-h", "15", "www.google.com"
PS> tracert $arguments

File extensions

  • PS1 – Windows PowerShell shell script
  • PS1XML – Windows PowerShell format and type definitions
  • PSC1 – Windows PowerShell console file
  • PSD1 – Windows PowerShell data file (for Version 2)
  • PSM1 – Windows PowerShell module file (for Version 2)

Application support

SnapIns and hosts

Application

Version

Cmdlets

Provider

Management GUI

Exchange Server

2007

402

Yes

Yes

Windows Server

2008

Yes

Yes

No

Microsoft SQL Server

2008

Yes

Yes

No

System Center Operations Manager

2007

74

Yes

No

System Center Virtual Machine Manager

2007

Yes

Yes

Yes

System Center Data Protection Manager

2007

Yes

No

No

Windows Compute Cluster Server

2007

Yes

Yes

No

Microsoft Transporter Suite for Lotus Domino[38]

08.02.0012

47

No

No

Microsoft PowerTools for Open XML[39]

1.0

33

No

No

IBM WebSphere MQ[40]

6.0.2.2

44

No

No

Quest Management Shell for Active Directory[41]

1.1

40

No

No

Special Operations Software Specops Command[42]

1.0

Yes

No

Yes

VMware
Infrastructure Toolkit[43]

1.5

157

No

No

Internet Information Services[44]

7.0

54

Yes

No

Ensim Unify Enterprise Edition[45]

1.6

Yes

No

Yes

Windows 7 Troubleshooting Center[46]

6.1

Yes

No

Yes

Microsoft Deployment Toolkit

  

  

  

  

 
 

 
 

0 comments: