Explain get-process | group-object for Powershell 2.0

Posted on 2012-09-21
Last Modified: 2012-10-01
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.
Question by:samiam41
    LVL 15

    Expert Comment

    by:David L. Hansen
    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.
    LVL 9

    Author Comment

    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?
    LVL 37

    Accepted Solution


    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.

    LVL 8

    Assisted Solution

    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.
    LVL 67

    Assisted Solution

    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
    LVL 9

    Author Closing Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
    Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
    The viewer will learn how to back up with the free utility from runtime software, DriveImageXML using Windows 7. Download DriveImageXML from Open folder where it was saved: Start installation by double clicking the install scrip…
    The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now