Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gets Windows server resource usage
Invoke-Command -ComputerName $server -Credential $cred {
$npmem = Get-Counter -Counter "\Memory\Pool Nonpaged Bytes" -MaxSamples 1 -SampleInterval 1
[PSCustomObject]@{
Hostname = $env:COMPUTERNAME
"w3wp(MB)" = [math]::Round((Get-Process w3wp | Measure-Object WorkingSet -Sum).sum / 1MB,2)
"NonPaged(GB)" = [math]::Round($npmem.CounterSamples.cookedvalue / 1gb,2)
}
}
foreach ($server in $servers.hostname[0]) {
Invoke-Command -ComputerName $server -Credential $cred {
$available = Get-Counter '\Memory\Available MBytes'
$total = (Get-WmiObject -class "cim_physicalmemory" | Measure-Object -Property Capacity -Sum).Sum / 1MB
$used = $total - $available.CounterSamples.CookedValue
[PSCustomObject]@{
Hostname = $env:COMPUTERNAME
Memory = [math]::Round($used / $total,2)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment