Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
My first PowerShell script that I knocked together to do one thing. Can I admit that I kinda liked PowerShell?
# Quick & dirty PowerShell script for polling Windows PerfMon counters and dumping into a CSV file
# setup PowerShell internals
$1GBInBytes = 1GB
$Computer = $env:COMPUTERNAME
# Set the log destination directory
$LogDir="C:\MTGLogs\"
# Set the performance counters below
# customize as needed
$perfcounters = @("\Memory\Available Bytes",
"\Memory\Committed Bytes",
"\Memory\Pages/sec",
"\PhysicalDisk(_Total)\Current Disk Queue Length",
"\PhysicalDisk(_Total)\% Disk Time",
"\Processor(_Total)\% Processor Time"
"\Processor(_Total)\Interrupts/sec",
"\System\Processor Queue Length",
"\Network Interface(dw1520 wireless-n wlan half-mini card)\Output Queue Length",
"\Network Interface(dw1520 wireless-n wlan half-mini card)\Bytes Received/sec",
"\Network Interface(dw1520 wireless-n wlan half-mini card)\Bytes Sent/sec");
# set up the file names and paths for logs
$date = Get-Date -Format 'yyyy_MM_dd-HH_mm_ss'
$LogFile = "$LogDir\Perfs_log_$date.csv"
# create the log directory if missing
if( !(test-path $LogDir)) {New-Item $LogDir -type directory}
#
# get the performance counters.
# Set -SampleInterval in seconds (currently every 10 sec.)
# Set -MaxSamples in number of samples (e.g. for 5 minutes of samples set to 30)
# can also use -continous instead of -MaxSampes n to run until stopped
Get-Counter -counter $perfcounters -SampleInterval 10 -MaxSamples 60 | export-counter -Path $LogFile -FileFormat CSV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.