Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active May 18, 2018 17:22
Show Gist options
  • Save magnetikonline/6d10482566ee972e80fe to your computer and use it in GitHub Desktop.
Save magnetikonline/6d10482566ee972e80fe to your computer and use it in GitHub Desktop.
PowerShell if expressions cheatsheet.

PowerShell if expressions cheatsheet

String
Is equal (case insensitive) if ($VAR1 -eq $VAR2)
Is equal (case insensitive) * if ($VAR1 -ieq $VAR2)
Is equal (case sensitive) if ($VAR1 -ceq $VAR2)
Regular expression ** if ($VAR1 -match "RegExp")
Numeric
Is equal if ($VAR1 -eq $VAR2)
Not equal if ($VAR1 -ne $VAR2)
Less than if ($VAR1 -lt $VAR2)
Less than or equal if ($VAR1 -le $VAR2)
Greater than if ($VAR1 -gt $VAR2)
Greater than or equal if ($VAR1 -ge $VAR2)
Array
Contains if (@("one") -ccontains "one")
Not contains if (@("one") -notcontains "one")
  • * By default all PowerShell all comparison operators are case-insensitive.
    • Prefixing with i makes this explicit.
    • Prefixing with c makes this case-sensitive.
  • ** Regular expression matches will be available in $Matches[].

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment