Get-DbaDiskSpace
View SourceSynopsis
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.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | true (ByValue) |
| Default Value | $env:COMPUTERNAME |
-Credential
Credential object used to connect to the computer as a different user.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| 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.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value | GB |
| Accepted Values | Bytes,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.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| 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.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| 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.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value | False |
-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.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value | False |
-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.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value | False |
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 in the specified unit (default GB)
- Free: Free space available in the specified unit (default GB)
- 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.
dbatools