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
ReTweet this Tip!