How to pass arguments to PowerShell scripts

How to pass arguments to PowerShell scripts

You can pass arguments to PowerShell scripts.

This is almost the same as at the command prompt.

They are passed in the script as $args[0],$args[1]… … and so on.

Save as a.ps1 below.

Write-Host $args[0]
Write-Host $args[1]

Run this script.

PS C:\work_ps> ./a.ps1 a b
a
b
PS C:\work_ps>

If there are no arguments on the command line, they are ignored.

The first argument is $args[0]. Then 1,2,3… and so on.

コメント

Discover more from 株式会社CONFRAGE ITソリューション事業部

Subscribe now to keep reading and get access to the full archive.

Continue reading

Copied title and URL