dbatools is a free PowerShell module with over 180 SQL Server administration, best practice and migration commands included.


This function returns database file space information for a SQL Instance or group of SQL Instances. Information is based on a query against sys.database_files and the FILEPROPERTY function to query and return information. The function can accept a single instance or multiple instances. By default, only user dbs will be shown, but using the IncludeSystemDBs switch will include system databases,




To check a SQL Server instance:

Get-DbaDatabaseFreespace -SqlServer localhost

Filter only files that are greater than 80% used.

Get-DbaDatabaseFreespace -SqlServer localhost | Where-Object {$_.PercentUsed -gt 80}

Use the pipeline to query multiple SQL Server instances

@(‘localhost’,’localhost\namedinstance’) | Get-DbaDatabaseFreespace


File free space script borrowed and modified from Glenn Berry’s(@GlennAlanBerryDMV scripts.


This command was created by Mike Fal. You can find Mike on Twitter, mikefal.net and LinkedIn.


From PowerShell, execute Get-Help Get-DbaDatabaseFreespace -Detailed for more information on this function.

Source Code

Want to see the source code? View Get-DbaDatabaseFreespace.ps1 on GitHub

Related commands