Powershell: Conditions

  PowerShell, Programming

Conditions

Terrinaries

  • -eq Equal To
  • -ne Not Equal To
  • -le Less than or Equal To
  • -lt Less than
  • -ge Greater than or Equal To
  • -gt Greater than

Boolians

  • -and And: ($x -eq $y -and $i -ne $j)
  • -or Or: ($x -eq $y -or $i -ne $j)
  • -xor: ($x -eq $y -xor $i -ne $j)
  • -not (expression):  -not ($x -eq $y)
    • !(Expression): !($x -e1 $y)

If / ElseIf / Else Statements

if ($someVar -eq $anotherVar){
  Write-Host "Yay! They are the same!"
} ElseIf ($someVar -lt $anotherVar){
 Write-Host "Whoops! $someVar is less than $anotherVar!"
} Else {
 Write-Host "Wow! $someVar is greater than $anotherVar!"
}

Switch Statements

$cuteCrazy = "Average"
Switch($cuteCrazy) {
  "Cute" {
     Write-Host "She's Cute"
     break
  }
  "Average" { Write-Host "She's Average."; break }
  "Crazy" { 
    Write-Host "Stay away from that, bruh!"
    break
  }
}

 

LEAVE A COMMENT