Power Shell
Power Shell
Power Shell
Purpose
The purpose of this cheat sheet is to describe some common options and techniques for
use in Microsoft’s PowerShell.
PowerShell Overview
PowerShell Background
Launching PowerShell
PowerShell is accessed by pressing Start -> typing powershell and pressing enter. Some
operations require administrative privileges and can be accomplished by launching
PowerShell as an elevated session. You can launch an elevated PowerShell by pressing Start
-> typing powershell and pressing Shift-CTRL-Enter.
PS C:\> Get-ChildItem
1/9
Find text within a file:
PS C:\> Get-Location
PS C:\> Get-Process
PS C:\> Get-Service
Paginating output:
2/9
PS C:\> Get-FileHash -Algorithm SHA1 file.txt
PS C:\> (New-Object
System.Net.WebClient).DownloadFile("http://10.10.10.10/nc.exe","
nc.exe")
PS C:\> Get-HotFix
3/9
PS C:\> cd HKLM:\
PS HKLM:\> ls
PS C:\> Get-ItemProperty
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\run
PS C:\>
[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.Ge
tBytes("PSFTW!"))
Syntax
Cmdlets are small scripts that follow a dashseparated
verb-noun convention such as "Get-Process".
Similar Verbs with Different Actions:
Parameters:
Each verb-noun named cmdlet may have many parameters to control cmdlet functionality.
Objects:
The output of most cmdlets are objects that can be passed to other cmdlets and further
acted upon. This becomes important in pipelining cmdlets.
4/9
Finding Cmdlets
To get a list of all available cmdlets:
PS C:\> Get-Command
Getting Help
To get help with help:
PS C:\> Get-Help
Detailed help:
Usage examples:
5/9
PS C:\> Get-Help <cmdlet> -examples
Cmdlet Aliases
Aliases provide short references to long commands.
PS C:\> Get-Alias
Efficient PowerShell
Tab completion:
PS C:\> get-child<TAB>
PS C:\> Get-ChildItem
6/9
PS C:\> ls –recurse
is equivalent to:
PS C:\> ls -r
5 PowerShell Essentials
Shows help & examples
Alias
PS C:\> Get-Command
Alias
Alias
PS C:\> [cmdlet] | gm
7/9
PS C:\> ForEach-Object { $_ }
Alias
PS C:\> Select-String
Alias
PS C:\> 1..10
8/9
PS C:\> 1..10 | % {echo "Hello!"}
PS C:\> $tmol = 42
PS C:\> ls variable:
Additional Info
The original SANS PowerShell Pocket Reference Guide (B&W TriFold) is available here:
Original SANS PowerShell CheatSheet
A printable PDF version of the cheatsheet using this format is available here:
SANS PS CheatSheet
9/9