Advertisement
Guest User

Get-Handles Script

a guest
Mar 29th, 2016
571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $allhandles = get-process
  2. $today = [DateTime]::Now
  3. $thisComputer = $env:computername
  4.  
  5. foreach($handle in $allhandles){
  6.     $data = ""
  7.     if($handle.handlecount -gt 2500)
  8.         {
  9.         if($handle.ProcessName -eq "lsass" -or $handle.ProcessName -eq "System" -or $handle.ProcessName -eq "Store" -or $handle.ProcessName -eq "sqlserver") {
  10.          }
  11.         else{
  12.         $data = $today,  $handle.ProcessName, $handle.handlecount | Out-File "C:\temp\handles.log" -Append
  13.             if($handle.HandleCount -gt 10000)
  14.                  {
  15.                 Send-MailMessage -To SYSADMIN@YOURDOMAIN.COM -From ALERT@YOURDOMAIN.COM -Subject "Excessive handle count detected: $thisComputer" -Body "An open file with a high handle count has been deteced. $handle.ProcessName - $handle.HandleCount" -SmtpServer SMTPSERVER.YOURDOMAIN.COM
  16.                  }
  17.              }
  18.         }
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement