Creators Update: number of processes

Page 4 of 4 FirstFirst ... 234

  1. Posts : 13,930
    Windows 10 Pro X64 21H1 19043.1503
       #31

    Doesn't work, get the same result with or without Sort-Object.
      My Computers


  2. Posts : 260
    Win 10 Pro X64
       #32

    There's a way to regroup the services as per the tutorial below from the Winaero site

    Set Split Threshold for Svchost in Windows 10 - Winaero
      My Computer


  3. Posts : 136
    Windows 10 Pro
    Thread Starter
       #33

    Ztruker said:
    Doesn't work, get the same result with or without Sort-Object.
    It's strange but this works for me:

    $array=get-process |where-object {$_.ProcessName -Match "svchost"}|Select Id
    $names=foreach($item in $array.Id){
    Get-WmiObject -Class win32_service -Filter "ProcessID='$item'" | select DisplayName
    }
    $names | sort-object DisplayName
      My Computer


  4. Posts : 13,930
    Windows 10 Pro X64 21H1 19043.1503
       #34

    JoeMcLutz said:
    It's strange but this works for me:

    $array=get-process |where-object {$_.ProcessName -Match "svchost"}|Select Id
    $names=foreach($item in $array.Id){
    Get-WmiObject -Class win32_service -Filter "ProcessID='$item'" | select DisplayName
    }
    $names | sort-object DisplayName
    Yes, that works perfectly for me as well, many thanks.
      My Computers


  5. Posts : 136
    Windows 10 Pro
    Thread Starter
       #35

    Ztruker said:
    Yes, that works perfectly for me as well, many thanks.
    Ooh! Fine! You're welcome: I'm happy for you! :)
      My Computer


  6. Posts : 5,478
    2004
       #36

    Ztruker said:
    Doesn't work, get the same result with or without Sort-Object.
    That is because the |sort-object is within the foreach loop. So each time it is sorting 1 thing.

    It is saying for every process (sorted by Id ), I'm going to find its name using Get-WmiObject. Then I'll sort that (one specific) DispayName.

    Obviously the results will be the same as you are still sorting by Id even though you have then further sorted the DispayName for the Id (which is unique anyway).

    Another method is to put all the results from the foreach loop into another array (for example $names).

    This appears slower because rather than writing out one line at a time to the console it does them all. It isn't slower btw just doesn't keep you updated.

    You can then sort $names by DisplayName rather than Id as it then has the information it wants to sort by.

    Or indeed output $names with or without sorting toOut-GridView and sort using the GUI.

    I've been idly thinking about it but haven't come up with a more elegant solution. More of a StackOverflow question though really...
    Last edited by lx07; 13 Apr 2017 at 05:44.
      My Computer


  7. Posts : 13,930
    Windows 10 Pro X64 21H1 19043.1503
       #37

    lx07 said:
    Or indeed output $names with or without sorting to Out-GridView and sort using the GUI.
    Using the GUI to sort is a nice idea. Works well too. Thank you.
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 18:00.
Find Us




Windows 10 Forums