• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 688
  • Last Modified:

Explain get-process | group-object for Powershell 2.0

Greetings.  I am well into the PowerShell tutorial and ran into a command that I am not so sure I understand.  The tutorial is explaining the use of the Group-Object cmdlet and I tried it on iexplore which returned a value I don't understand so I need a little explanation.

>get-process | group-object iexplore
Count Name                      Group
----- ----                      -----
   71                           {System.Diagnostics.Process (AESTSr64), Syst...

I checked task manager and only see 3 instances of iexplore running.  I ran get-process from PS and only see 3 instances.  What does the 71 mean then?

Thanks in advance.  I'm still learning PS so I appreciate your time and patience.
3 Solutions
David L. HansenProgrammer AnalystCommented:
Try the same command on something other than iexplore, perhaps notepad.  I believe what is happening is this: since internet-explorer is so deeply integrated into Windows, other running  "processes" (like file-explorer, etc.) may be affecting the total count.
samiam41Author Commented:
Hey sl8rz.  Thanks for the quick response.  Here is the result for Notepad:

PS Alias:\> get-process | group-object notepad

Count Name                      Group
----- ----                      -----
   68                           {System.Diagnostics.Process (AESTSr64), Syst...

:)  No notepad open.  This is on a laptop which I turned on this morning so I doubt it is the amount of times that I have opened that item "today".  Maybe lifetime of the image?  Maybe I'm talking out my rear?
Jamie McKillopIT ManagerCommented:

Group-Object will group the results based on the object properties. "iexplorer" is not a property it is a value of a property. If you run "get-process | group-object name" you will get a list of each running process with the count for each process.

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Brent ChallisPrincipal: ITCommented:
Get-Process | Group-Object Name

Then you will see how many instances of each process name are running.  In terms of the code you listed you could try:

get-process notepad | group-object Name
and see how many instances of Notepad are running, you should get an error if there are none.
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
The explanation is correct, you need to provide a property, not a value, for group-object. That is because group-object is not a filter, but an aggregation, of values - it collects the same value for the property(s) you specify (or the first one it finds, if you do not). So it is useful if you want to measure the count of more than one process name, and want to maintain the process objects (then contained as an collection, accessible like an array). For example
   get-process n* | 
   group-object Name |
   % { write-host $_.Name, $_.Count, ($_.Group | measure-object vm -Sum).Sum }

Open in new window

calculates the overall virtual memory of each instance of processes starting with "n".

The error message appearing if you use
  get-process Notepad
without having any Notepad running can be suppressed either by providing an ErrorAction value:
  get-process Notepad -ea SilentlyContinue
or a wildcard:
  get-process Notepad* | group-object Name
but it is much better if you want to know the count only to ask for exactly that:
  @(get-process Notepad*).Count
samiam41Author Commented:
Thanks for everyone's help with this.  I can honestly say I learned a lot from it and look forward to working with you all again in the near future.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now