0

I want to compare two Lists of Arrays and to display the Delta in a third array:

$ListOfVMs
$ListOfRunningVMs

$StoppedVMs = $ListOfVMs | { Where-Object $_.Name -notcontains $ListOfVMs.Name }

This Filter delivers still the complete Content of $ListOfVMs and not only the Delta. What I am doing wrong?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, I was not specific enough. I am using the Pipe!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.