Thor Logo dbatools

Get-DbaDiskSpace

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

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 and filesystem type.

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>]
    [[-ExcludeDrive] <String[]>]
    [-CheckFragmentation]
    [-Force]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example 1: Get disk space for the server srv0042

PS C:\> Get-DbaDiskSpace -ComputerName srv0042

Example 2: Get disk space for the server srv0042 and displays in megabytes (MB)

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

Example 3: Get disk space from two servers and displays in terabytes (TB)

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

Example 4: Get all disk and volume space information

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

Example 5: Get all disk and volume space information

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

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

Displays the Capacity and Free values in the specified unit: Bytes, KB, MB, GB or TB.
By default each value picks a human friendly unit for display (“1.82 TB”). The underlying values are not changed, and every unit stays available through the SizeIn* and FreeIn* properties of the
output object.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
Accepted ValuesBytes,KB,MB,GB,TB
-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

This parameter is deprecated and will cause the command to stop with a warning.
The fragmentation analysis was removed from this command because the underlying DefragAnalysis call took minutes per volume.

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

Outputs

Dataplat.Dbatools.Computer.DiskSpace

Returns one object per disk volume on the target computer(s). The output includes comprehensive disk space information retrieved from Windows WMI, with capacity and free space available in multiple unit formats (Bytes, KB, MB, GB, TB, PB).

Default display properties (shown without using Select-Object):

  • ComputerName: The name of the computer
  • Name: The volume name (drive letter or UNC path, e.g., ‘C:' or ‘\server\share’)
  • Label: The volume label/name if assigned
  • Capacity: Total disk capacity, displayed in a human friendly unit or in the unit requested with -Unit
  • Free: Free space available, displayed in a human friendly unit or in the unit requested with -Unit
  • PercentFree: Percentage of disk space that is free
  • BlockSize: File system block size in bytes

Additional properties available (use Select-Object * to view):

  • FileSystem: File system type (NTFS, FAT32, ReFS, etc.)
  • Type: Drive type identifier (corresponds to DriveType)
  • DriveType: Enumerated drive type (LocalDisk, RemovableDisk, NetworkDrive, etc.)
  • IsSqlDisk: Boolean indicating if SQL Server files are detected on this disk
  • Server: Server name (same as ComputerName)

Size information in all units (dynamically calculated):

  • SizeInBytes, FreeInBytes: Capacity and free space in bytes
  • SizeInKB, FreeInKB: Capacity and free space in kilobytes
  • SizeInMB, FreeInMB: Capacity and free space in megabytes
  • SizeInGB, FreeInGB: Capacity and free space in gigabytes
  • SizeInTB, FreeInTB: Capacity and free space in terabytes
  • SizeInPB, FreeInPB: Capacity and free space in petabytes By default, only local disks (DriveType 2) and removable disks (DriveType 3) are returned. Use -Force to include all drive types (network drives, CD/DVD, etc.). Use -ExcludeDrive to filter out specific volumes.