Advertisement
nullzilla

Monitor - Large Outlook Files

Mar 31st, 2023 (edited)
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Monitor Large Outlook Files
  2. Import-Module $env:SyncroModule -DisableNameChecking
  3.  
  4. $LargeFileSize = '45' # In gigabytes (Outlook default maximum size is 50GB, can be changed via registry)
  5.  
  6. # Sanitize and convert input to bytes
  7. $LargeFileSize = [int64]$LargeFileSize.Replace('GB', '') * 1GB
  8.  
  9. # Get Outlook files from all user profile folders
  10. $OutlookFiles = @(Get-ItemProperty "$env:SystemDrive\Users\*\AppData\Local\Microsoft\Outlook\*.ost")
  11. $OutlookFiles += Get-ItemProperty "$env:SystemDrive\Users\*\AppData\Local\Microsoft\Outlook\*.pst"
  12. $OutlookFiles += Get-ItemProperty "$env:SystemDrive\Users\*\Documents\Outlook Files\*.pst"
  13.  
  14. # Look for large Outlook files and output in our preferred format
  15. $LargeOutlookFiles = foreach ($OutlookFile in $OutlookFiles) {
  16.     if ($OutlookFile.Length -gt $LargeFileSize) {
  17.         [PSCustomObject] @{
  18.             'Filename'      = -join $OutlookFile.Name[0..65] # Trim to keep table formatting
  19.             'Size in GB'    = [math]::Round(($OutlookFile.Length / 1GB), 2) # Convert to GB with 2 decimal places
  20.             'Last Modified' = $OutlookFile.LastWriteTime
  21.         }
  22.     }
  23. }
  24.  
  25. if ($LargeOutlookFiles) {
  26.     $LargeOutlookFiles = $LargeOutlookFiles | Out-String
  27.     $LargeOutlookFiles
  28.     Rmm-Alert -Category 'Outlook' -Body "Large Outlook Files Found: $LargeOutlookFiles"
  29. } else {
  30.     "No large Outlook files found."
  31.     Close-Rmm-Alert -Category 'Outlook'
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement