You may do the following:
$StoppedVMs = $ListOfVMs | Where-Object Name -notin $ListOfRunningVMs.Name
You need to pipe to Where-Object
. Where-Object
is what contains the script block (if you need to use it). You are also not comparing both lists here as you only reference $ListOfVMs
.
Since you are comparing a single item against a collection, you will want to use -notin
if the single item is on the left-hand side (LHS). -notcontains
would be used if the collection is on the LHS.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…