Menu & Search
Get Disk Space of a SQL Server

Get Disk Space of a SQL Server

You can quickly check disk space info on a SQL Server host by running the query below. I sometimes find this the quickest way to check available space rather than using PowerShell or the Windows GUI. This SQL Script only work on SQL Server 2008 R2 and above.

   CONVERT(DECIMAL(18,2),vs.total_bytes/1073741824.0) AS [Total Size (GB)],
   CONVERT(DECIMAL(18,2), vs.available_bytes/1073741824.0) AS [Available Size (GB)],
   CONVERT(DECIMAL(18,2), vs.available_bytes * 1. / vs.total_bytes * 100.) AS [Space Free %]
FROM sys.master_files AS f WITH (NOLOCK)
CROSS APPLY sys.dm_os_volume_stats(f.database_id, f.[file_id]) AS vs
ORDER BY vs.volume_mount_point OPTION (RECOMPILE);

The query result will be returned within a blink, and look like this.

SQL Server Disk Space Query Result.

The PowerShell cmdlet below will also get you the information you need. If running on a remote server, use Enter-PSSession to connect to the target server first (requires Local Admin permissions).

PowerShell Get-Volume.