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

Please note that documentation and command names may be out of date while we work furiously towards 1.0


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.

Get-Help

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