How Does Member Enumeration Work in PowerShell 3?

PowerShell is doing the hard work for us and it loops over the collection internally. I like to call this “implicit foreach”. Assuming the member you specified is present on each object, if the member you specified is a property, you get back its value. If it’s a method, it invokes the method on the each object.

In v2, to get all process names you had to take care of looping yourself:

Get-Process | Foreach-Object {$_.Name}

In v3, the equivalent would be:

(Get-Process).Name

Same applies to methods. To kill all processes with name starting with note*:

(Get-Process note*).Kill()

Leave a Comment