Solved

How to write formatted get-process output to a file

Posted on 2015-01-12
2
121 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 82

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

708 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

17 Experts available now in Live!

Get 1:1 Help Now