I have simple script which takes array argument:
param(
[Parameter(Mandatory=$true)]
[string[]]$keys
)
for ($i = 0; $i -lt $keys.Length; ++$i) {
Write-Host "$i. $($keys[$i])"
}
I need to execute it via powershell with -File argument (in order to address a TeamCity bug) like so:
powershell.exe -File Untitled2.ps1 -keys a
How can I pass parameter as array to my script? As long as I pass single key it works well, but it don't want to take more than one element.
I tried following among others:
powershell.exe -File Untitled2.ps1 -keys a,b
powershell.exe -File Untitled2.ps1 -keys:a,b
powershell.exe -File Untitled2.ps1 -keys $keys # where $keys is an array
Whatever I'd tried either I have "A positional parameter cannot be found" error, or all keys are joined in first array element.
Any ideas?
"a","b"or@("a","b")? orstart-processwith-argumentlist?