Skip to content

Instantly share code, notes, and snippets.

@sunnyc7
Created November 17, 2019 13:27
Show Gist options
  • Save sunnyc7/34d28e08f8d8d3bcda0b13cec62264b3 to your computer and use it in GitHub Desktop.
Save sunnyc7/34d28e08f8d8d3bcda0b13cec62264b3 to your computer and use it in GitHub Desktop.
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