Created
July 13, 2018 11:10
-
-
Save taddison/e2affea7b72c4c75d425eb27d335df05 to your computer and use it in GitHub Desktop.
Restart a windows service using more memory than a given cutoff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -RunAsAdministrator | |
$serviceName = "BITS" | |
$cutoffGB = 0.0001 | |
$processId = (Get-WMIObject win32_service | where { $_.name -eq $serviceName}).ProcessID | |
$process = Get-Process -Id $processId | |
$workingSet = $process.WorkingSet64 | |
$workingSetGB = $workingSet / 1GB | |
if($workingSet -gt $cutoffGB) { | |
Write-Warning "Service using $workingSetGB GB" | |
Restart-Service -Name $serviceName -Verbose | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment