Collections:
Other Resources:
Run Script with Arguments in Windows PowerShell
How to write a script that take argument from the command line in Windows PowerShell?
✍: FYIcenter.com
You can use the automatic variable $Args to take arguments from the command line where the script is launched.
The $Args variable contains an array of all argument provided at the command line where this script was launched.
Here is sample script on how to use $Args variable:
<# My-Ping.ps1 - Tests network connection to a remote server #> If ($Args.Length -eq 2) { Test-Connection $Args[0] -Count $Args[1] } Else { "Usage: " " My-Ping server_name test_count" }
If you run it without argument, you will get
PS C:\fyicenter> .\My-Ping.ps1 Usage: My-Ping server_name test_count
If you run it with correct arguments, you will get
PS C:\fyicenter> .\My-Ping.ps1 www.yahoo.com 2 Destination IPV4Address Bytes Time(ms) ----------- ----------- ----- -------- www.yahoo.com 98.139.183.24 32 52 www.yahoo.com 98.139.183.24 32 51
⇒ Work with File System in Windows PowerShell
⇐ Execution Status and Errors in Windows PowerShell Scripts
2016-10-27, 1817🔥, 0💬
Popular Posts:
What is "Lenovo Camera Mute" in a service on Lenovo laptop computer that supports the camera on/off ...
Why I am getting this "Microsoft Silverlight Update" pop up window? If you have Silverlight 2.0 inst...
How to increase the remote login limit on Windows 10? By default, Windows 10 only allows 1 remote lo...
How to verify IIS configuration for PHP scripts? If you have followed our Configuring IIS for PHP Sc...
What is "Superfetch" in my Windows XP service list? And how is "Superfetch" service related to SysMa...