Powershell Switch Statement to Set Multiple Variables

Question:

I am in the process of converting some old VB script to Powershell. I am trying to use a Switch statement to set multiple variables. Is this possible in Powershell? In VBS my code would look something like this:

I have tried something similar in PS, but it doesn’t seem to set the variables.

When I check the value of either DESTDRV or SRCDRV I get an error saying: The variable ‘$SRCDRV’ cannot be retrieved because it has not been set. Any ideas on what I’m doing wrong?

Answer:

Are you setting $cENV first?

I’m running that exact script above like this:

And it’s returning

Source:

Powershell Switch Statement to Set Multiple Variables by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply