Prof. Powershell

Process Possibilities

The PowerShell team is sneaky. They've given you some extra properties in objects that you can use to your advantage.

I bet that one of the first cmdlets you learned in Windows PowerShell was Get-Process. You probably even created filters of processes and properties like this:

PS C:\> get-process | where {$_.handles -gt 1000} | sort handles -Descending | Select Name,ID,WorkingSet,Handles

If so, that is great. But did you know that the PowerShell team tucked in some other ways for you to look at processes? First, the process object has a few “extra” properties added by the PowerShell team which you can see when you pipe Get-Process to Get-Member. Try this from your PowerShell session:

PS C:\> get-process | select psconfiguration

PSConfiguration is a property set, or a pre-defined collection of object properties. Theoretically this should make it easier for an administrator to get useful information. You can take this property set even further with a command like this:

PS C:\> get-process | select psconfiguration | sort PriorityClass | format-table -GroupBy PriorityClass -Property Name,ID,FileVersion

Another defined PropertySet is PSResources.

PS C:\> get-process | select PSResources

You're still getting an object which you can sort, filter, export or convert. But you don't have to figure out what property names to use or type them.

Another way you can get a different take on processes is with a formatting cmdlet. The default is Format-Table which is what you get when you just run Get-Process. By try this:

PS C:\> get-process | format-list

A little different isn't it? Because formatting is at the end you can't do anything else other than outputting to a file or printer. If you want to manipulate the objects, you'll need to do it before formatting.

PS C:\> get-process | sort CPU -descending | select -first 5 | format-list

PowerShell also has a little recognized feature called a View. Some object types have different “views” depending on the formatting cmdlet. These are defined in the DotNetTypes.format.ps1xml configuration file and are unfortunately not easy to discover. But I'll point out the process related ones here. First, try this on for size:

PS C:\> get-process | format-table -view Priority

or this:

PS C:\> get-process | format-table -view starttime

I hope you'll keep poking around PowerShell because you never know what you might find.

About the Author

Jeffery Hicks is an IT veteran with over 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He is a multi-year recipient of the Microsoft MVP Award in Windows PowerShell. He works today as an independent author, trainer and consultant. Jeff has written for numerous online sites and print publications, is a contributing editor at Petri.com, and a frequent speaker at technology conferences and user groups.

comments powered by Disqus
Most   Popular

SharePoint Watch

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.