added Get-MemoryUsage and Stop-MemoryHog
This commit is contained in:
@@ -650,8 +650,26 @@ function Create-LocalUser {
|
||||
}
|
||||
Else { LogMsg "Cannot create or modify a local account without administrative privileges" }
|
||||
|
||||
## TODO: Hide account from logon screen
|
||||
#Get-ChildItem "HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList"
|
||||
If ( $Hide ) {
|
||||
# TODO: Hide account from logon screen
|
||||
#Get-ChildItem "HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList"
|
||||
}
|
||||
}
|
||||
|
||||
# Returns the number of MB a process is consuming
|
||||
function Get-MemoryUsage ([string]$AppName) {
|
||||
[math]::Round((Get-Process -Name $AppName -ErrorAction SilentlyContinue | Measure-Object -Property WorkingSet -Sum).Sum / 1MB)
|
||||
}
|
||||
|
||||
# Kills a process if it's using more than the specified amount of memory
|
||||
function Stop-MemoryHog ([string]$AppName,[int]$MemoryLimit) {
|
||||
$MemoryUsed = (Get-MemoryUsage -AppName $AppName)
|
||||
If ( $MemoryUsed -gt $MemoryLimit ) {
|
||||
$MemoryDifference = $MemoryUsed - $MemoryLimit
|
||||
LogMsg "Killing ""${AppName}"" for using ${MemoryDifference}MB over the limit of ${MemoryLimit}MB"
|
||||
Try { Get-Process -Name $AppName -ErrorAction SilentlyContinue | Stop-Process -Force }
|
||||
Catch { LogErr $_.Exception.Message }
|
||||
}
|
||||
}
|
||||
|
||||
Setup-MSPDirectories
|
||||
|
||||
Reference in New Issue
Block a user