Show Disk Usage

Version: SCCM 2012 R2

I was recently asked to calculate disk usage for machines in our environment. By default, SCCM inventories (via Hardware Inventory) size for logical disks. However, it does not calculate disk usage. To obtain disk usage, simply enable the Free Space setting for Hardware Inventory. And then perform the necessary disk usage calculation in your SQL query.

To begin hardware inventory of Free Space, go to the following area within the admin console:

  • Administration ->  Client Settings -> Right-click “Default Client Settings” and select Properties -> Hardware Inventory -> click on Set Classes
  • Expand “Logical Disk (SMS_LogicalDisk)”
  • Place a check on “Free Space (MB)”
  • Click OK.

This will instruct all clients to update policy for Hardware Inventory and begin reporting Free Space in MB.

Depending on the hardware inventory scan cycle, it may take a few days to obtain metrics from all machines. When machines report both size of logical disks along with free space, both numbers will be in megabytes (MB). Subtracting logical disk size minus free space will yield usage. This query will perform the subtraction along with the conversion of megabytes (MB) to gigabytes (GB). In addition, it will also calculate the free space percentage for each logical disk.

select SystemName0 as 'Machine Name', DeviceID0 as 'Logical Drive', FileSystem0 as 'File System', convert(decimal(20,0),round(1.0*Size0/1024,0)) as 'Capacity GB',
convert(decimal(20,0),round(1.0*(Size0-FreeSpace0)/1024,0)) as 'UsedSpace GB', convert(decimal(20,0),round(1.0*FreeSpace0/1024,0)) as 'FreeSpace GB',
convert(decimal(20,1),round((cast(FreeSpace0 as decimal)/ cast(Size0 as decimal) * 100),1)) as 'Percent Free',
VolumeName0 as 'Volume Name'
where (Size0 is not null) and (FreeSpace0 is not null)
Order by Systemname0, DeviceID0