guyrleech

Find processes with non standard processor affinity set

May 15th, 2020
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [int]$vcpus = (Get-CimInstance -classname win32_processor|measure-object -Property NumberOfLogicalProcessors -Sum).Sum
  2.  
  3. [int]$affinityMask = [math]::Pow( 2 , $vcpus ) - 1
  4.  
  5. ## https://docs.microsoft.com/en-gb/dotnet/api/system.diagnostics.process.processoraffinity?view=netframework-1.1#System_Diagnostics_Process_ProcessorAffinity
  6.  
  7. Get-Process | where-object { $_.ProcessorAffinity -and $_.ProcessorAffinity.ToInt32() -ne $affinityMask } | select-object name,id,sessionid,starttime,ProcessorAffinity,@{n='BinaryAffinity';e={ [convert]::ToString( [string]$_.ProcessorAffinity , 2 )}},@{n='Processors';e={[int]$n=$_.ProcessorAffinity;[int]$bits=0;while($n) { $bits += ($n -band 1) ;$n = $n -shr 1 };$bits }}|Format-Table -AutoSize
Add Comment
Please, Sign In to add comment