• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 680
  • 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.
0
samiam41
Asked:
samiam41
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.
0
 
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?
0
 
Jamie McKillopCommented:
Hello,

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.

JJ
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
Brent ChallisPrincipal: ITCommented:
Try:
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.
0
 
QlemoC++ DeveloperCommented:
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
0
 
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.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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