PowerShell Version 3 Language Improvements - Part 1

Member Enumeration

In PowerShell Version 2, I found myself quite often running a cmdlet, then piping that cmdlet to Select-Object -Expand PropertyName, for example:


In PowerShell Version 3, the same result can be acheived by running:


Not only is the new syntax easier to use, but it's also quicker, see below. The old method takes 36 seconds to run, the same command using the new method, 16 seconds!


In addition to the improvement listed above. Length and Count properties have been made available to all variables, even if the variable isn't an array, see below:


This is designed to assist in looping logic, so you don't need to determine if an object is just one or many before you go ahead and loop through it. Previously, I got around this using foreach.

PSItem

In PowerShell Version 2, You had to use the $_ variable to represent the current pipeline object. In PowerShell Version 3, you can use the $PSItem alias, which is much easier on the eye/fingers.

Popular posts from this blog

Get local computer UUID/GUID using Windows Powershell

gPLink and gPOptions

PSLoggedOn Getting Started on Windows Server 2008 R2