PowerShell If statements need to be written in a particular syntax. Let’s look at some examples below.
Equals
In the example below, we test for equals. Note the notations -eq:
$a = 1 $b = 2 If ($a -eq $b) { Write-Output "Equal" } Else { Write-Output "Not Equal" }
Greater Than
In the example below, we test for equals. Note the notations -gt:
$a = 1 $b = 2 If ($a -gt $b) { Write-Output "Greater than" } Else { Write-Output "Not greater than" }
You can also use ge (greater than or equal to), lt, le etc.
Note the order can be switched.
Boolean
Let’s look at a true/false example below, which produces false:
$a = $false If ($true -eq $a) { Write-Output "true" } Else { Write-Output "false" }
THANKS FOR READING. BEFORE YOU LEAVE, I NEED YOUR HELP.
I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.
IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.
THANK YOU, AND LET'S KEEP LEARNING TOGETHER.
CARL