Windows PowerShell 3.0 simplified syntax

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.

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top