I am trying to pass an array to a PowerShell script, but I always get just one value. I have googled my butt off, but I can't find anything. All I need to do is pass an array to the script. Here is my code:
param($Location)
($location).count
Foreach ($loc in $Location)
{
$loc
}
Here is my command I am running:
C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe -ExecutionPolicy Unrestricted -File "C:\ParaTestingArray.ps1" -location Sydney,London
Here is the output:
1
Sydney
For the life of me I can't get it to grab the other value in the array. I have tried using
param([string[]]$Location)
I have tried:
-location "Sydney","London"
-location @(Sydney,London)
-location Sydney London
-location Sydney,London
-location (Sydney,London)
What am I doing wrong?
Use the -command
switch instead.
Like this:
powershell -Command "&{C:\ParaTestingArray.ps1 -Location A,B,C}"
From the about_powershell:
For writing a string that runs a Windows PowerShell command, use the format:
"& {<command>}"
Where the quotation marks indicate a string and the
invoke operator (&
) causes the command to be executed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With