Share via


Powershell command to extract Memory (Private Working Set) and Description from Task Manager Processes

Question

Monday, February 4, 2013 1:13 PM

Hi all, 

I am trying to get a log file to produce Memory (Private Working Set) and Description. But I want to search for specific processes on a Windows 2008 R2 Server. 

Below I have tested on my laptop but how do I also convert the output to MB or GB.

Memory (Private Working Set) and Description

PS H:\> get-process -name "firefox", "chrome", "outlook"

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
                     -- 
    101      13    14812      20624   183    35.79    756 chrome
    117      14    49340      60204   184    11.37    824 chrome
    118      12    35848      52776   178     1.20   1084 chrome
    184      11    71428      65280   255    40.83   3988 chrome
    919      30   135920     148520   351   100.61   4488 chrome
    108      10    50828      53572   195    21.70   5540 chrome
    531      39   271740     291352   563   346.62   6040 firefox
   4354      74   113232     182800   671   313.64   4152 OUTLOOK

All replies (13)

Monday, February 4, 2013 7:43 PM ✅Answered | 2 votes

Get-WMIObject Win32_Process -Filter "Name='w3wp.exe' or Name='bgmonitorservice.exe'"  | Sort PrivatePageCount |
    Select Name,CommandLine,@{n="Private Memory(gb)";e={$_.PrivatePageCount/1gb}} | Out-File -Width 200 result.txt

Monday, February 4, 2013 1:31 PM | 2 votes

try:

get-process chrome | select-object PrivateMemorySize, Description, Name

If you want to convert to MB or GB, you can do something like:

get-process chrome | select name, description, @{l="Private Memory (MB)"; e={$_.privatememorysize / 1mb}}

I'd recommending looking at "Get-Member" cmdlet so you can see what is available. For example "get-process | get-member" will show you all of the exposed properties. I'd also suggest reading the help on the select-object cmdlet (get-help select-object).

Hope this helps!  

G. Samuel Hays


Monday, February 4, 2013 1:50 PM

Thank you for your quick reply, do you have an idea what the cmdlet is for "Command Line" instead of Description? 

and how to Search using "Command Line" paths rather than searching using Image Name/ Description? 


Monday, February 4, 2013 1:53 PM | 1 vote

get-process chrome | select path 

You might also want to have a look at the data in this way:

get-process chrome | select -first 1 | select *

G. Samuel Hays


Monday, February 4, 2013 2:12 PM

thanks for that, it helped me quite abit, why doesn't the full paths appear when extracting this as a txt file, if you look below it has a lot of "...." and i am looking to get this full path below in the image to extract 

Name                          Path                          Modules                                 Private Memory (gb)
                                                                                     
w3wp                          c:\windows\system32\inetsr... {System.Diagnostics.Proces...             0.149967193603516
w3wp                          c:\windows\system32\inetsr... {System.Diagnostics.Proces...             0.163120269775391




Monday, February 4, 2013 2:37 PM | 1 vote

Get-WMIObject Win32_Process | Select Name,CommandLine,@{n="Private Memory(gb)";e={$_.PrivatePageCount/1gb}}


Monday, February 4, 2013 2:45 PM

Thanks for your reply how to i get the output file to display the full path? it keeps on coming out like below? 

Name                                    CommandLine                                                  Private Memory(gb)
                                                                                      
System Idle Process                                                                                                   0
System                                                                                               0.0001068115234375
smss.exe                                \SystemRoot\System32\smss.exe                                0.0005035400390625
csrss.exe                               %SystemRoot%\system32\csrss.exe Obje...                     0.00287246704101563
wininit.exe                             wininit.exe                                                 0.00153732299804688
csrss.exe                               %SystemRoot%\system32\csrss.exe Obje...                     0.00164031982421875

Monday, February 4, 2013 3:22 PM | 1 vote

CommandLine shows the actual command issued to start the process. In the event of services, Environment Variables are used and that is reflected there. 

G. Samuel Hays


Monday, February 4, 2013 4:07 PM | 1 vote

Get-WMIObject Win32_Process | Select Name,CommandLine,@{n="Private Memory(gb)";e={$_.PrivatePageCount/1gb}} | Out-File -Width 200 result.txt

Monday, February 4, 2013 6:56 PM

Thanks for your reply, I have given it ago and that part worked thanks. 

I want to search "w3wp", "bgmonitorservice" but my script is not working and i'm not sure why, can you help me with making it work please and i'm trying to make the name in ascending order but all is failing... 

$Names = "w3wp", "bgmonitorservice"
Get-WMIObject Win32_Process $Names | Select Name,CommandLine,@{n="Private Memory(gb)";e={$_.PrivatePageCount/1gb}} |Out-File -Width 200 desktop\result.txt

Monday, February 4, 2013 6:59 PM | 1 vote

Get-WmiObject Win32_Process -Filter "Name='w3wp.exe' or Name='bgmonitorservice.exe'" | Select ......


Monday, February 4, 2013 7:39 PM

I know this is long winded but I am trying to work this out, i got the result below when I tried the command line and also I do not think the results was inputted out to be in ascending order

>> Get-WmiObject Win32_Process -Filter "Name='w3wp.exe' | Select Name,CommandLine,@{n="Private Memory(gb)";e={$_.Private
PageCount/1gb}} |oUT-FILE -WIDTH 200 desktop\result.txt
>>
The term 'gb' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling
 of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:98
+ Get-WmiObject Win32_Process -Filter "Name='w3wp' | Select Name,CommandLine,@{n="Private Memory(gb <<<< )";e={$_.Priva
tePageCount/1gb}} |oUT-FILE -WIDTH 200 desktop\result.txt
    + CategoryInfo          : ObjectNotFound: (gb:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Monday, February 4, 2013 7:57 PM

I have just tested it, and it did work just that some output results were not in order by "name" 

but many thanks for your help, i appreciate this