I'd generally design this type of script to leverage Exchange Management Shell and dynamically query all servers in the appropriate site in the mailbox role (to automatically accommodate server adds and removals over time). But in this case I wanted this script to be 'blind' to Exchange version differences and also avoid a dependency on Exchange Management Shell. A specific goal in this case was to provide a tool to enable junior admins to evaluate the drive status after backup failure alerts, without the need to run the queries from a machine with a specific version of the Exchange Management Tools installed. So I instead use semicolon-delmited string variables to statically store arrays of server names for processing within the script itself.
Here's a broad outline of the script's processing:
- Prompt for any missing parameters
- Split my pre-defined delimited string varibles of target servers per site into arrays
- Use the Get-Wmiobject cmdlet to retrieve the name, driveletter, capacity, & freespace attributes of matching local drives (drivetype=3), filtering on either the drive letter (for non-mountpoint local drives), or on no-drive letter, to identify mountpoint drives, and then re-filter for a distintive Transaction-Log-identifying folder name substring, to target the Tlog drives in isolation from the array of all mountpoints (including database drives) on the mountpoint root drive.
- For flexibility, I chose to build my WMI query as a string -- adding and dropping appropriate syntax for the query, depending on the type of target server -- and then use the Invoke-Expression cmdlet to execute the command. Note: I use the tee cmdlet to feed the resulting output to both the console and an email-able attachment file.
- From there, the script uses the standard send-mailmessage cmdlet to email the output report to the specified admin address.
And the current revision can always be found at Github: get-Tlogs-FreeSpace-Report.ps1