1

I have a batch file (runPowerShell.bat) with the following line:

Powershell.exe -ExecutionPolicy ByPass -File %psFile% %2 %3 %4 %5

%1 is psFile in which the powershell file is passed in

%2 is another argument i intend to pass later

%3 is the arg i wanna print for now

The powershell file (scriptWrapper.ps1) contains this:

param($App_input)

$Script = "$($args[2])" #%2 for process or sync

write-host $Script

There is another PowerShell file called

Process.ps1

that i wish to pass as %3 argument, meaning $args[2]

if i say write-host "$args[2]" it prints like this:

Process.ps1[2]

so it kinda works but i dont want the positional parameter with it, so I followed this thread for guidance, and the solution ($($args[2])) makes sense, but I am unsure why its not working for me

accessing the $args array in powershell

it prints nothing:

Not printing

Cataster
  • 3,081
  • 5
  • 32
  • 79

1 Answers1

2

I figured out why...

so apparently, args does not bode well with param().

I had param($App_input) that takes %1 for an app input first before the Process.ps1 input for %2. and since param() has to be defined at the top of the script, it seems to have an unfriendly effect with args.

WHen i commented out param(), $($args[1]) printed out fine

however, instead of args, i should have just easily added $Script in param

param($App_input, $Script)

much better now

Cataster
  • 3,081
  • 5
  • 32
  • 79