I call a script: "TestArgs1 xxx -T". From within TestArgs1, I call TestArgs2, trying to pass it the same arguments. If I use: "TestArgs2 @args", switch -T is correctly passed as true. Also if I copy $args to another array and pass it, it works. But if I create my own array first, (in order to modify some arguments), switch -T is passed as false. Why is this? How can I correctly pass the switch argument? See sample code below:
###### TestArgs1
Write-Host "#### pass incoming args ###"
TestArgs2 @args
Write-Host "#### copy incoming args ###"
$a = $args
TestArgs2 @a
Write-Host "#### pass created array ###"
$b = "xxx", "-T"
TestArgs2 @b
###### TestArgs2
function Main {
param ($n, [switch] $t, [switch] $d)
"n = $n"
"t = $t"
}
Main @args
The output of this is the follows:
#### pass incoming args ###
n = xxx
t = True
#### copy incoming args ###
n = xxx
t = True
#### pass created array ###
n = xxx
t = False
When I create my own array and pass the same arguments, t shows up as false.