How to pass values to nested ForEach?

Question:

I am trying to use a variable created in an outer ForEach loop inside an inner ForEach loop. The value does not pass thru as I expect and is always null.

Notice The value for $server is always null can you tell me why and how to fix?

Answer:

Pass in the parameters via the -ArgumentList parameter e.g.:


Here’s a simple example of using -ArgumentList:

Source:

How to pass values to nested ForEach? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply