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, ∼3373🔥, 0💬
Popular Posts:
What is NicConfigSvc.exe process - Internal Network Card Power Management Service? Process nicconfig...
What is "Net Driver HPZ12" in my Windows 7 service list? And how is "Net Driver HPZ12" service relat...
How to remove msjava.dll - Java Console Extra Tools Menu Item for Internet Explorer (IE) browsers? m...
How to set up Internet Explorer 8, or IE 8? After downloading Internet Explorer 8. or IE 8, you shou...
What is the file extension .VOB (DVD-Video Object or Versioned Object Base)? .VOB is the file extens...