Your basic ITPro blog... What's going on at work, what I'm interested in.

Thursday, August 28, 2008

New Love for One-Liners

Hey Scripting Guy! answered a question about 'svchost' and what services this process is actually hosting. I've seen svchost listed in Task Manager, but never really put any thought into what it was doing there.

In any case, the Scripting Guys posted a script, about ten lines long, that reports the services running in each svchost PID. Check it out at the link above.

Now, if you have been reading along, you know that I am trying to learn to think "pipeline" when it comes to Powershell. To that end, I thought it would be fun to try and come up with a one-liner to output the same information. Here's what I came up with.

gps -n svchost | %{$_.Id} | %{gwmi Win32_Service -f "processID = $_"} | group processid | %{$_.group} | select processID, Name, state, startMode

It's not a short one-liner, but it returns essentially the same information as the script. In case the line is too long:

gps -n svchost | %{$_.Id} | %{gwmi Win32_Service -f "processID = $_"} | 
group processid | %{$_.group} | select processID, Name, state, startMode

No comments:

Additional Info

My photo
email: support (AT) mangrumtech (DOT) com
mobile: 480-270-4332