PowerShell Scripts, Tips, Expert Advices, Forums, and Resources

Welcome to PowerShell.com, the educational and community site for Windows PowerShell People. Get a quick overview.

As a Powershell.com member you will have access to:

  • Daily PowerShell tips written by Microsoft MVPs and other leading Windows PowerShell experts
  • Free Windows PowerShell advice and training provided by Microsoft MVPs and other leading Windows PowerShell experts
  • Access to leading Windows PowerShell blogs
  • A free ebook, Mastering PowerShell, written by Microsoft MVP Dr. Tobias Weltner
PowerTip of the Day

Shortening Parameter Arguments in PowerShell 3.0

In PowerShell 3.0, when a parameter expects a fixed list of values, you do not need to write the complete argument. It is OK to write just as much as is needed to uniquely identify the argument:

Write-Host 'This is a colorful message' -ForegroundColor r -BackgroundColor y

This produces a red text on yellow background.

Using shortcuts like this isn't very useful, though, because at the same time PowerShell 3.0 introduces argument completion. So after you typed "r" as argument to -ForegroundColor, simply press TAB to make PowerShell complete the argument. This is just as quick and produces much better code:

Write-Host 'This is a colorful message' -ForegroundColor Red -BackgroundColor Yellow

Twitter This Tip! ReTweet this Tip!

Copyright 2012 PowerShell.com. All rights reserved.