PowerShell Conditionals

Conditionals

Type Operator Comparison test
Equality eq equals
ne not equals
gt greater than
ge greater than or equal
lt less than
le less than or equal
matching like string matches wildcard pattern
notlike string does not match wildcard pattern
match string matches regex pattern
notmatch string does not match regex pattern
Replacement replace replaces strings matching a regex pattern
Containment contains collection contains a value
notcontains collection does not contain a value
in value is in a collection
notin value is not in a collection
Type is both objects are the same type
isnot the objects are not the same type

Where this or that

$pnpDevices | ? { $_.Status -Match "Error|Warning|Degraded|Unknown" } | Select Status,Name,InstanceID

If

If And

If (condition1 -And condition2) {Do stuff}
# An alternative explanation would be

If (test1 -And test2) {
execute block command when true
}

If not

If (-Not ($true)) {Do Stuff}

If (!($true)) {Do Stuff}