Solved

How to write formatted get-process output to a file

Posted on 2015-01-12
2
131 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

734 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