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


Get-DbaDatabaseFreespace

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,

Screenshots

Get-DbaDatabaseFreespace

Examples

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

References

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

Author

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. Want to see the source code? See it on GitHub