Find-ExchangeDBFreeSpace


posted by Richard Giles
02-27-2009

Downloads: 437
File size: 1.8kB
Views: 1,402

Embed
Find-ExchangeDBFreeSpace
  1. # Jonathan Medd 
  2. # http://jonathanmedd.blogspot.com/2009/01/using-powershell-to-find-free-space-in.html 
  3. # Find free space in Exchange 2003 databases 
  4.  
  5. # Check to see if csv exists and if so remove it 
  6. if (Test-Path "FreeSpaceGreaterThan1GB.csv"
  7.     Remove-Item "FreeSpaceGreaterThan1GB.csv" 
  8.  
  9. #Set the columns for the csv file 
  10. $rows = "Servername," + "Mailbox Store," + "Free Space (MB)," 
  11. Add-Content FreeSpaceGreaterThan1GB.csv $rows 
  12.  
  13. $ExchServer = 'server1','server2' 
  14. foreach ($Server in $ExchServer
  15.     #Get the time 1 day ago in the right format for WMI query 
  16.     $WmidtQueryDT = [System.Management.ManagementDateTimeConverter]::ToDmtfDateTime([DateTime]::Now.AddDays(-1)) 
  17.     #Perform WMI query of Event 1221 in Application log in the last day 
  18.     $1221 = Get-WmiObject -computer $ExchServer -query ("Select * from Win32_NTLogEvent Where Logfile='Application' and Eventcode = '1221' and TimeWritten >='" + $WmidtQueryDT + "'"
  19.      
  20.     foreach ($event in $1221
  21.     
  22.         #Get the name of the Mailbox Store 
  23.         $MBXStoreLocationStart = $event.Message.IndexOf("Storage Group") + 16 
  24.         $MBXStoreLocationFinish = $event.Message.IndexOf("has") -
  25.         $MBXStoreLocation = $event.Message.SubString($MBXStoreLocationStart, $MBXStoreLocationFinish - $MBXStoreLocationStart
  26.          
  27.         #Get the free space figure and convert it to an integer 
  28.         $MBLocationStart = $event.Message.IndexOf("has") +
  29.         $MBLocationFinish = $event.Message.IndexOf("megabytes") -
  30.         $MBLocation = $event.Message.SubString($MBLocationStart, $MBLocationFinish - $MBLocationStart
  31.         $result = [int]$MBLocation 
  32.          
  33.         $ComputerName = $event.ComputerName 
  34.          
  35.         #If free space > 3GB, add the details to the csv file 
  36.         if ($result -ge 3072) 
  37.         
  38.             $rowline = "$ComputerName," + "$MBXStoreLocation," + "$MBLocation," 
  39.             Add-Content FreeSpaceGreaterThan1GB.csv $rowline 
  40.         
  41.     
Filed under: , ,

Find free space in Exchange 2003 databases.

Attributed To: Jonathan Medd

URL: http://jonathanmedd.blogspot.com/2009/01/using-powershell-to-find-free-space-in.html

 

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.