Windows PowerShell 3.0 simplified syntax

by Mitch Tulloch [Published on 12 Dec. 2012 / Last Updated on 25 Sept. 2012]

A tip showing an example of how the simplified syntax of Windows PowerShell 3.0 makes commands and scripts easier to read.

One of the improvements in version 3.0 of Windows PowerShell is the simplification of the syntax for the Where-Object cmdlet.  For example, to display a list of all installed roles and features on a server, pipe the output of the Get-WindowsFeature cmdlet into the Where-Object cmdlet and use Where-Object to filter out everything except roles and features whose InstallState property is equal to Installed:

Get-WindowsFeature -ComputerName SEA-SRV-1 | Where-Object InstallState -eq Installed

You may have wondered why the above command didn’t look like this:

Get-WindowsFeature - ComputerName SEA-SRV-1 | Where-Object {$_.InstallState -eq Installed}

The reason is because Windows PowerShell 3.0 lets you eliminate the script block notation (the curly braces), the current object placeholder ($_), and the dot property notation. These improvements make PowerShell code easier to understand.

Mitch Tulloch is a eight-time recipient of the Microsoft Most Valuable Professional (MVP) award and widely recognized expert on Windows administration, deployment and virtualization.  This tip was excerpted from his new book Installing and Configuring Windows Server 2012 Training Guide published by Microsoft Press which is available from Amazon.  For more tips by Mitch you can follow him on Twitter or friend him on Facebook.

See Also

The Author — Mitch Tulloch

Mitch Tulloch is a well-known expert on Windows Server administration and cloud computing technologies. He has published over a thousand articles on information technology topics and has written, contributed to or been series editor for over 50 books.

Featured Links