<img height="1" width="1" src="https://www.facebook.com/tr?id=1529264867168163&amp;ev=PageView &amp;noscript=1">
blog_listing_hero_img.jpg

Using PowerShell to Report on Exchange Server Disk Space

Disk space is vital to the health of an Exchange Server. Without disk you don’t have email. Exchange is dependent on having disk because every time an email is sent it’s written to disk, without it you’re S.O.L.

When exchange databases run out of disk space the databases will dismount. Dismounted databases are usually not a good thing because that means email is down for the users in that database. Systems with low disk space can also impact overall performance of the server. Any of these events happening to an exchange server is not good. We all know that when email is slightest bit slow or down, the users will react like the zombies are attacking and the sky is falling.

Keep the zombies away…

If you are using tools such as Mailscape, System Center Operations Manager, or Spotlight, monitoring Exchange disk space can be pretty easy. If your budget does not allow for third party software, however, you are left to monitor their servers manually. Manually monitoring anything can be a pain and not practicable for some shops due to the size of their environment. This is especially true if you’re running an environment with multiple Exchange 2010 DAG nodes, with replicating databases across many mount point paths.

All is not lost, however, if you are familiar with PowerShell. Using PowerShell you can report on your Exchange disks pretty easily using the get-wmiobject cmdlet. You can use this cmdlet with the win32_volume parameter to report on all your volumes, including your mount point paths.

The example below will generate a CSV file containing your Exchange servers’ drive space, the size of the databases, and the amount of available free space.

$servers = get-exchangeserver

Get-WmiObject -computer $servers win32_volume|

select-object __SERVER,Name,

@{Name="Capacity(GB)";expression={[math]::round(($_.Capacity/ 1073741824),2)}},

@{Name="FreeSpace(GB)";expression={[math]::round(($_.FreeSpace / 1073741824),2)}},

@{Name="Free(%)";expression={[math]::round(((($_.FreeSpace / 1073741824)/($_.Capacity / 1073741824)) * 100),0)}}|

export-csv c:\scripts\filename1.csv

 

The csv export looks like the sample image below:

Fig1_CSV


PowerShell Report Exchange Server Disk Space 1 resized 600

Refine your data

As you can see it will report on all your volumes….even those tiny system partition; do you really care to see that in your report? Most people just care about the actual LUNs and mount point paths.

To make the report look cleaner you’ll need to use where-object cmdlet to filter out the data that only gives you the volumes that you want. For example, if you just wanted to view actual volumes (which include all the mount point paths) you can filter on attributes that will present only the desired volumes. In this case we do not want to see any volumes labeled with “system reserved” and a blank caption.

where-object {$_.caption -ne $null -and $_.label -ne “System Reserved” -and $_.drivetype -eq 3}

 

$servers = get-exchangeserver

 

Get-WmiObject -computer $servers win32_volume|where-object {$_.caption -ne $null -and $_.label -ne “System Reserved” -and $_.drivetype -eq 3}|select-object __SERVER,Name,

@{Name="Capacity(GB)";expression={[math]::round(($_.Capacity/ 1073741824),2)}},

@{Name="FreeSpace(GB)";expression={[math]::round(($_.FreeSpace / 1073741824),2)}},

@{Name="Free(%)";expression={[math]::round(((($_.FreeSpace / 1073741824)/($_.Capacity / 1073741824)) * 100),0)}}|export-csv c:\scripts\filename.csv

 

The output of the filtered attributes looks like the below sample:

Fig2_csv

PowerShell Report Exchange Server Disk Space 2 resized 600

Now this version of the report is much cleaner, giving you only the data you want to see. If you want to automate this report you can save it as a PowerShell script and schedule a task to run the script on your server.

We hope this information was helpful! If you found this article interesting, you may want to continue reading other PowerShell articles here

For more information about the author you can visit our "Meet the Authors" page.