Where and Foreach Methods in PowerShell version 4

It's a little over a month until Microsoft TechEd North America 2014 which is in Houston this year. I was trying to remember the cool stuff I saw at TechEd last year and Desired State Configuration along with the announcement about PowerShell version 4 were the two big things I remember, but let's not forget about some of the other things such as the new Where and Foreach methods.

I certainly don't claim to be an expert with these, but I'm going to provide a couple of examples for documentation for myself as well as to get you thinking about them:

The Where method:

1((Get-Command -Name Get-WMIObject).parameters.values).where{
2$_.name -eq 'ComputerName'} |
3Select-Object -Property Name, Aliases

2014-04-02_18-10-41.png

The Foreach method:

1('dc01', 'sql01', 'web01').foreach{
2Get-WinEvent -ComputerName $_ -LogName System -MaxEvents 1 |
3Select-Object -Property MachineName, Id, LevelDisplayName, Message}

2014-04-02_17-44-58.png

My first thought is the syntax seems to be insane, but I remember thinking the same thing years ago when I first saw the curly brace dollar sign underscore and so on: {$_.property}.

µ