views:

153

answers:

6

I'm trying to make a script that will place a list (in a .csv file) of processes that are running that take up more than 10 mb of RAM and shows the time + date the script was run. My teacher did this during his lecture but I can't remember how he did it. Just trying to figure out how to be better at IT.

So my question is, can anyone help me with this? I don't even know where to start.

A: 

You need to use the 'tasklist' command and then filter by memory usage.

zaf
A: 

Windows operating systems now ship with an alternate shell to cmd called PowerShell

Here is how you would do it in Powershell.

ps | where-object { $_.workingset -gt 10000000 } | Out-File c:\list.csv

Kindness,

Dan

Daniel Elliott
+1  A: 

try this

set var=%DATE% %TIME%
echo %var%>c:\tasklist2.csv
tasklist /fi "memusage gt 10000" /fo csv>>c:\tasklist2.csv 

in the real world you don't get Vista or Win7....unfortunately

Keng
A: 

use the tasklist command eg

tasklist /FI  "Memusage gt 10000" /NH

use date /T or time /T to create date and time.

ghostdog74
A: 

You could also add the date to the filename here.

set var=%DATE% %TIME%
set var1=%DATE%
set var1=%var1:/=%
set var1=%var1:~-8%
echo %var%>c:\tasklist%var1%.csv
tasklist /fi "memusage gt 10000" /fo csv>>c:\tasklist%var1%.csv 
Keng
+1  A: 

You can do this in PowerShell like so:

Get-Process | Where {$_.PM -gt 10MB} | 
    Export-Csv "memhogs-$(Get-Date -uf %Y%m%d%H%M).csv

or using aliases

gps | ?{$_.PM -gt 10MB} | epcsv "memhogs-$(Get-Date -uf %Y%m%d%H%M).csv
Keith Hill