The PowerShell script below:
1. Queries the environment for a list of Exchange servers.
2. Creates a file with information about total and remaining disk space.
3. E-mails the file.
################################################## # Script : DiskSpace.ps1 # Author : Tom Anderson - http://tomandersonpro.net # Date : 13-03-2013 # Purpose : This script checks the disk size and free space in Gigabytes for each # : Exchange server in your environment that runs Exchange 2007 or newer # : A report is created and sent out via email to address specified. # History : ################################################## #### Set parameters for output filename $date = ( get-date ).ToString('yyyyMMdd') $file = New-Item -type file "C:\Temp\ExchangeDailyChecksHistory\$date-ExchangeFreeDiskSpace.txt" -Force #### E-mail variables $smtpServer = "EXSVR" $recipient = "[email protected]" $sender = "[email protected]" $Subject = "Daily Exchange Server disk space report" $Body = "Please find report attached." #### Poll Exchange environment to retrieve any servers newer than 2007 #### (I used this filter as for some reason an Exchange 2003 box was reporting as being in the environment, despite having been removed some time ago) $servers=Get-ExchangeServer |where-object {$_.isExchange2007OrLater -eq $True} #### Set values for progress counter $serverscount = $servers.count;$i=0 #### Loop through each server retrieved foreach ($server in $servers) { #### Get disk space 'Get Disk Space ' + $server |out-file $file -append get-wmiobject -computer $server -query ` "Select * from win32_logicaldisk ` where DriveType=3" | sort DeviceId | format-table DeviceId, VolumeName, @{Label="Size in GB"; Expression={[math]::round(($_.Size/1GB),2)}}, @{Label="Free space in GB"; Expression={[math]::round(($_.FreeSpace/1GB),2)}} -auto | out-file $file –append } #### Send message Send-MailMessage -From "$sender" -To "$recipient" -Subject "$Subject" -Body "$body" -Attachments "$file" -smtpserver "$smtpServer"
This has been listed on TechNet Script Center at http://gallery.technet.microsoft.com/scriptcenter/E-mail-disk-space-info-for-8ef4ed29
Leave a Reply