A. In my April 15, 2008, FAQ (" Q: How can I use Windows PowerShell to get a count of all of my machine's services?"), I created a service count using a Foreach loop, which increased a counter by 1 for each object returned from the Get-Service command, as the following code shows:

get-service | foreach \{$t=0\} \{$t +=1\} \{"Total services: $t"\}

A number of readers pointed out that I should've used the Measure-Object cmdlet with the following commands:

get-service | measure-object | select count

The output would be:


If I hadn't included the | select count command, the computer would have outputted other counts that don't apply to what I wanted, such as information about averages, sums, maximums, and minimums of the values passed.