Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
April 14, 2008
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:
Usersjohn.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.
You May Also Like