I am making an OS call in PowerShell to get a working set for a specific process.
When the working set is <2 GB, the value is returned correctly.
When the working set is between 2 and 4 GB, the value is returned as a negative number. I can use it with 4294967295, multiply by -1 and get the correct value.
Everything was fine in the world ... until the working set exceeded 4 GB. Now the return value seems to be counting from 4 GB ... IOW, I need to add the result to 4294967296.
My bitwise operational chops are a bit rusty, and I'm not sure if there is a way to accurately calculate the correct value depending on what the OS returns. Ideally, I would like to have one expression that does this work, or at least a series of "if" statements.
Here's the PS code if it clarifies the situation. it only accurately calculates the working set for values <4 GB.
$ServerName = "MyServer" # get a collection containing all process objects on the system $Procs = (Get-Process -ComputerName $ServerName) | Sort-Object -Descending WS # Output each process and its working set foreach($Proc in $Procs) { $WorkingSet = [int64]($Proc.WorkingSet64) #for values greater than 2^32, a negative value will be returned... need to convert to 64 bit: if($WorkingSet -lt 0) { $WorkingSet = 4294967295 -bxor $WorkingSet * -1 } $Process = $Proc.ProcessName Write-Host "Process: $process" Write-Host "Working Set: $WorkingSet" Write-Host "------------------------------" }
source share