dbatools

Get-DbaDiskSpace

View Source
Chrissy LeMaire (@cl), netnerds.net , Jakob Bindslet
Windows, Linux, macOS

Synopsis

Retrieves disk space and filesystem details from SQL Server host systems for capacity monitoring and performance analysis.

Description

Queries Windows disk volumes on SQL Server systems using WMI to gather critical storage information for database administration. Returns comprehensive disk details including capacity, free space, filesystem type, and optional fragmentation analysis.

Essential for SQL Server capacity planning, this function helps DBAs monitor disk space before growth limits impact database operations. Use it to verify adequate space for backup operations, identify performance bottlenecks from fragmented volumes hosting data or log files, and maintain compliance documentation for storage utilization.

By default, only local disks and removable disks are shown (DriveType 2 and 3), which covers most SQL Server storage scenarios. Hidden system volumes are excluded unless the Force parameter is used.

Requires Windows administrator access on target SQL Server systems.

Syntax

Get-DbaDiskSpace
    [[-ComputerName] <DbaInstanceParameter[]>]
    [[-Credential] <PSCredential>]
    [[-Unit] <String>]
    [[-SqlCredential] <PSCredential>]
    [[-ExcludeDrive] <String[]>]
    [-CheckFragmentation]
    [-Force]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Get-DbaDiskSpace -ComputerName srv0042

Get disk space for the server srv0042.

Example: 2
PS C:\> Get-DbaDiskSpace -ComputerName srv0042 -Unit MB

Get disk space for the server srv0042 and displays in megabytes (MB).

Example: 3
PS C:\> Get-DbaDiskSpace -ComputerName srv0042, srv0007 -Unit TB

Get disk space from two servers and displays in terabytes (TB).

Example: 4
PS C:\> Get-DbaDiskSpace -ComputerName srv0042 -Force

Get all disk and volume space information.

Example: 5
PS C:\> Get-DbaDiskSpace -ComputerName srv0042 -ExcludeDrive 'C:\'

Get all disk and volume space information.

Optional Parameters

-ComputerName

Specifies the SQL Server host systems to query for disk space information. Accepts multiple computer names for bulk monitoring.
Use this to check storage capacity across your SQL Server environment before database growth or backup operations impact available space.

PropertyValue
Alias
RequiredFalse
Pipelinetrue (ByValue)
Default Value$env:COMPUTERNAME
-Credential

Credential object used to connect to the computer as a different user.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-Unit

This parameter has been deprecated and will be removed in 1.0.0.
All size properties (Bytes, KB, MB, GB, TB, PB) are now available simultaneously in the output object but hidden by default for cleaner display.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default ValueGB
Accepted ValuesBytes,KB,MB,GB,TB,PB
-SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-ExcludeDrive

Specifies drive letters to exclude from the disk space report, using the format ‘C:' or ‘D:'.
Use this to skip system drives or non-SQL storage when focusing on database file locations, or to exclude network drives that may cause timeouts.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-CheckFragmentation

Enables filesystem fragmentation analysis for all volumes, which can impact SQL Server I/O performance when database or log files are stored on fragmented drives.
This significantly increases runtime (seconds to minutes per volume) but provides critical data for troubleshooting slow database operations or planning defragmentation maintenance.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default ValueFalse
-Force

Includes all drive types and hidden volumes in the results, not just local and removable disks (DriveType 2 and 3).
Use this when you need complete storage visibility including network drives, CD/DVD drives, or system volumes that might host SQL Server components like backup locations or tempdb files.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default ValueFalse
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with “sea of red” exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this “nice by default” feature off and enables you to catch exceptions with your own try/catch.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default ValueFalse