A lot of companies have monitoring software that will generate a report showing the amount of storage used on all of your systems. Smaller organizations may lack this type of software and occasionally even if you have monitoring, it won’t provide the specific data you require.

You can use PowerShell for all types of system monitoring and reporting. By calling WMI (CMI) we can access nearly any component of a system and obtain its status. If you’re planning on following the instructions below from your workstation you’ll need to install the appropriate RSAT package from Microsoft or use PowerShell remoting to connect to a domain controller and import a session for the Active Directory module. It may be easier to run the script from a Domain Controller.

The first step our script needs to accomplish is to build a list of the systems we want to report on. For most windows networks that means importing the Active Directory PowerShell module and using its Get-ADComputer function.

Import-Module ActiveDirectory
$domains = (Get-ADForest).domains
$dcs = Foreach ($domain in $domains) {
Get-ADDomainController -DomainName $domain -Discover -Service PrimaryDC
$servers = Foreach ($dc in $dcs) {
Get-ADComputer -Properties * - Filter {(OperatingSystem -like "*Windows Server*")}|Select DNSHostname -ExpandProperty DNSHostName

The snippet above will find all the primary domain controllers in your AD Forest and then scan them for all computer objects who’s operating system properties contain the words “Windows Server”. It will store the dns hostnames of those systems in a variable named $servers. If you wanted to scan workstations instead (or add them to your report) you just need to alter the filter or add a line.

$workstations = Foreach ($dc in $dcs) {
Get-ADComputer - Properties * - Filter {(OperatingSystem -notlike "*Windows Server*")}|Select DNSHostName -ExpandProperty DNSHostName

Now that we have our list of systems to scan the rest is just a matter of using WMI to find the drives and their status. We’ll also toss in a little math to make a report that’s easier to read.

$report = Foreach ($server in $servers) {
Get-WMIObject Win32_Volume -Filter "DriveType = 3" -ComputerName $server|Where-Object {"Label -ne 'System Reserved'"}|Sort-Object Freespace|FT -Property @{Name = "Mount Point"; Expression = {$_.Caption}}, @{Name = "Capacity (GB)"; Expression = {[math]::Round(($_.Capacity/1GB),2)}}, @{Name = "Free Space (GB)"; Expression = {[math]::Round(($_.Freespace/1GB),2)}}, @{Name = "% Available"; Expression = {[math]::Round (($_.Freespace/$_.Capacity)* 100)}} -GroupBy SystemName -Autosize

Combine the snippets above into a script and you’ll have full functioning storage report. You can add a SendMail command and schedule it with the Windows Task Scheduler to create an automated report. It also wouldn’t be difficult to output the results to a HTML page somewhere to create a dashboard. There are a lot of possibilities once you understand the data collection techniques. For another alternative look at my Exchange storage report, its essentially the same script but finds and filters for your Exchange email servers.