Created
November 17, 2019 13:27
-
-
Save sunnyc7/34d28e08f8d8d3bcda0b13cec62264b3 to your computer and use it in GitHub Desktop.
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
Function Trim-WorkingSet { | |
[cmdletbinding()] | |
param([int] $procid) | |
begin { | |
$sig = @" | |
[DllImport("kernel32.dll")] | |
public static extern bool SetProcessWorkingSetSize( IntPtr proc, int min, int max ); | |
"@ | |
} | |
process { | |
$apptotrim = (get-process -Id $procid).Handle | |
Add-Type -MemberDefinition $sig -Namespace User32 -Name Util -UsingNamespace System.Text -PassThru | |
[User32.Util]::SetProcessWorkingSetSize($apptotrim,-1,-1) | |
} | |
} | |
#Infinite Loop | |
for (;;) { | |
Get-Process | foreach {Trim-WorkingSet -procid $_.Id} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment