C# passing an array to a powershell script


I’m attempting to run a powershell script from C#. I have no problem passing strings to the script however when I try to pass an array to the powershell script an exception gets thrown.
Here is the C# code:

Here is the powershell script:

Every time this code executes it throws:

I know that the code to execute the powershell script is correct when passing strings to the powershell script, it has been thoroughly tested.


It works perfectly fine for me.

Only thing I notice is that, in your script params you have $reponseCollection – the s is missing in response. Unless you made a mistake in entering it here, that would be the reason.

It might have seemed to work with string because Powershell doesn’t care ( normally) when you assign / use a non-existing variable. But when you index into a null / non-existing variable, it does throw the error.


C# passing an array to a powershell script by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply