Friday, November 11, 2011

Running PowerShell script with parameters

When running powershell from a command line and passing it one or more parameters, parameters passed in should be separated by a space and if any of the parameters contain spaces, they should be wrapped in double quotes:


C:\> .\MyPScript.ps1 "this is foirst parameter" "this is second"


And when accessing command line arguments from within the script, use args array with subscripts:


$param1=args[0]
$param2=args[1]

No comments:

Post a Comment