Using -contains for $null

Hello All,

Staring at something that is not making sense to me this morning… I need to scan volumes and return all the volumes on servers that have volumes formatted with ReFS or that have been borked and are now flagged as RAW.

$volumes = gwmi win32_volume

If ($Volumes.filesystem -contains 'ReFS' -or $null){
    "Found them"
}
Else {
    "Not there"
}

If I look for only $null - it works, finds them and returns True. It’s only when I join them with an -or that the $null stops being found. It does still rind the ReFS and return True, it just ignores the $null.

What am I doing wrong? How should I be doing it?

Hello, welcome back, it’s been a while :wave:

You need a conditional statement after the -or operator:

This should work:

(($Volumes.filesystem -contains 'ReFS') -or ($Volumes.filesystem -contains $null))
1 Like

Thanks Matt.

Duh oh! Of course! Too long looking at it!

Many thanks indeed.