A. The Get-Service cmdlet returns information about all services. You can easily pass this output to a loop that increments a counter. The following code provides an example:

Users\john.SAVILLTECH> Get-service | foreach \{$t=0\} \{$t +=1\} \{"Total services: $t"\}

The return is:

Total services: 144

How does this work? The Foreach cmdlet has three sections. The first runs the \{$t=0\} variable once to set it to zero. The second section, \{$t +=1\}, increments the variable by one for each service, and the final section, \{"Total services: $t"\}, displays the variable's value when the cmdlet finishes.