Windows PowerShell Quick Reference

How to Access Arguments

To access command-line arguments used when starting a script use the automatic variable $args. You can cycle through the individual arguments in the $args collection by using code similar to this:

foreach ($i in $args) {$i}

To access a particular argument use the collection index number, with 0 representing the first item in the collection, 1 representing the second item, etc:


You can reference the last item in a collection by using the index number –1:


How to Use Colored Text

To display text in a different color use the Write-Host cmdlet and specify a foreground color:

How to Get More Information

You can also specify a different background color: Continue reading “Windows PowerShell Quick Reference”