Reputation: 1642
I trying to write a PowerShell script (learning at the same time).
I have following named parameters
param([String] $Workspace = $pwd,
[String] $Files = "*",
[String] $Locales = "de,es,fr,it,nl,pt_BR,ru",
[String] $Exception = "TINP_D=TIGF,TIN_F=TIGD",
[Switch] $Verbose,
[Switch] $Whatif)
Lets say for the $Locales I am using split to loop through each locale with
foreach ($locale in $Locales.split(",")) {
So far so good. The problem starts when I specify a list of locales on command without double quotes, as it is detected as array of string and it becomes "de es fr" which in return breaks my code as it expects a CSV string.
And same goes for $Exception parameter but for that I split on comma then on equals sign.
Any Ideas, what should I be doing?
Upvotes: 0
Views: 1272
Reputation: 29479
There are more solutions, the easiest one is to alter the parameter so that it is array of strings
[String[]] $Locales = ('de', 'es', ...)
And then just iterate the array
foreach ($locale in $Locales)
Upvotes: 4