Skip to content

Instantly share code, notes, and snippets.

@clintcolding
Created February 18, 2019 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clintcolding/c160c8bfebf49bc539e0a7f3346f7f4e to your computer and use it in GitHub Desktop.
Save clintcolding/c160c8bfebf49bc539e0a7f3346f7f4e to your computer and use it in GitHub Desktop.
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