Solved

How to write formatted get-process output to a file

Posted on 2015-01-12
2
128 Views
Last Modified: 2015-01-12
I need a Powershell script to save the output of get-process to a text file.  It should have the following columns:  ProcessName, WS and CPU.  I tried this command:

get-process | sort-object WS -descending | select ProcessName, WS, CPU | add-content c:\temp\procmem.txt

It produced the following output:

@{ProcessName=iexplore; WS=378351616; CPU=134.6756633}
@{ProcessName=iexplore; WS=216297472; CPU=47.2527029}
@{ProcessName=OUTLOOK; WS=142602240; CPU=139.2620927}
...

I need it to look like this:

ProcessName           WS                        CPU
iexplore                      378351616         134.6756633
iexplore                      216297472         47.2527029
OUTLOOK                  142602240         139.2620927
...
0
Comment
Question by:McThump
2 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 40543869
Try
get-process | sort-object WS -descending | select ProcessName, WS, CPU | Format-Table -AutoSize | Out-String | add-content c:\temp\procmem.txt

Open in new window

0
 

Author Closing Comment

by:McThump
ID: 40544638
That works. Thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Synchronize a new Active Directory domain with an existing Office 365 tenant
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

830 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