Show Menu
Cheatography

PowerShell Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Variables

$var = "­str­ing­"
Assign
$a,$b = 0
Assign Multiple
$a,$b = 0,"s­tri­ng"
Assign Multiple
$a,$b = $b,$a
Flip
$var = [int]5
Strong Type
 

Flow Control

If ( test ) { } Elseif ( test2 ) { } else { }
while ( test ) { }
For($i = 0; $i -lt 10; $i ++) { }
Foreach ($var in $iterable) { use $var here }
99 .. 1 | foreach { use $_ }
 

Compar­isons and Logic

-eq / -ne
== / !=
-gt / -ge
> / >=
-lt / -le
< / <=
-match, -notmatch
regex matching
-like, -notlike
wildcard matching
-contains, -notco­ntains
does $left (not) contain $right
-in, -notin
is $left (not) in $right