How to pass an array into a PowerShell script from the OS


The following command line causes my script to throw due to missing arguments. The problem only happens when the -WebServerList parameter contains parentheses to denote an array.

This is launched by TeamCity, which I assume is making a simple Windows shell command and so its possible that the () are being interpreted by the shell/Windows.

However, I’ve tried DOS escaping e.g. ^( ... ^) and that doesn’t help. Invoking PowerShell scripts from Windows has always been hard work, afterall who’d wanna do a crazy thing like that right?!

In the mean time, I’m going to change my script to access a CSV in a single string and split it manually, so I can go home, but it’d be nice to know if there’s a proper way to handle this.


It seems like the issue is that array configuration cannot be correctly defined by the OS. You can achive something similar to what you want by using -Command instead of -File:

Cheers, Chris.

I took the liberty of editing your answer to demo the results, and prove it works.

From a DOS command prompt:


How to pass an array into a PowerShell script from the OS by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply