Shane O’Neill looks at variable scope within script blocks in Powershell:
Now what happens if we don’t want to use switch? What happens if we tried to do this with script blocks instead?
I’ve created 3 different script blocks here just for ease of use. If you want to create a single script block to do this then I encourage it! Let me know how you get on.
We’re also passing in the parameter into the script block by passing it in the brackets of the
.InvokeReturnAsIs()
method.
Read on and learn along with Shane.