Reputation: 155
So i have Powershell
script
and i want to know how to access its args
using Visual Studio
arguments window:
And this is how i try to use this arguments
:
Write-Host "here's arg 0: $($args[0])"
But currently this return empty string:
here's arg 0:
Upvotes: 0
Views: 285
Reputation: 125312
You need to close the project properties page, then open the file that you want to be as start-up script and press F5 to run the project.
This way the arguments which you entered in arguments Script Arguments will be passed to the script. Keep in mind the parameters will be passed to the script separated by space, so if space is part of a parameter, surround that parameter with quotation.
You can see the result in both Output window and PowerShell Interactive Window.
Example
Having script:
"Number of args: $($args.Count)"
for($i=0; $i -lt $args.Count; $i++)
{
"arg[$i]: $($args[$i])"
}
Setting following values as Script Argument:
"Some Value" "Another Value"
If you press f5, you will see the following result in output window:
PS C:\Example> C:\Example\Script.ps1
Number of args: 2
arg[0]: Some Value
arg[1]: Another Value
The program 'Script.ps1: PowerShell Script' has exited with code 0 (0x0).
Upvotes: 0