Skip to content

Instantly share code, notes, and snippets.

@blinds52
Forked from magnetikonline/README.md
Created April 15, 2017 18:52
Show Gist options
  • Save blinds52/4bfafef7bbe1913d60f8e4d12a3bce52 to your computer and use it in GitHub Desktop.
Save blinds52/4bfafef7bbe1913d60f8e4d12a3bce52 to your computer and use it in GitHub Desktop.
PowerShell if expressions cheatsheet.

PowerShell if expressions cheatsheet

<tr>
	<th colspan="2">Numeric</th>
</tr>
<tr>
	<td>Is equal</td>
	<td><code>if ($VAR1 -eq $VAR2)</code></td>
</tr>
<tr>
	<td>Not equal</td>
	<td><code>if ($VAR1 -ne $VAR2)</code></td>
</tr>
<tr>
	<td>Less than</td>
	<td><code>if ($VAR1 -lt $VAR2)</code></td>
</tr>
<tr>
	<td>Less than or equal</td>
	<td><code>if ($VAR1 -le $VAR2)</code></td>
</tr>
<tr>
	<td>Greater than</td>
	<td><code>if ($VAR1 -gt $VAR2)</code></td>
</tr>
<tr>
	<td>Greater than or equal</td>
	<td><code>if ($VAR1 -ge $VAR2)</code></td>
</tr>
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")
  • * By default all PowerShell all comparison operators are case-insensitive. Prefixing with i makes this explicit.
  • ** 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