Get-DbaDatabaseSpace

Returns database file space information for database files on a SQL instance.

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 databases will be shown, but using the IncludeSystemDBs switch will include system databases.

File free space script borrowed and modified from Glenn Berry’s DMV scripts (http://www.sqlskills.com/blogs/glenn/category/dmv-queries/)

Screenshots

dbatools - Get-DbaDatabaseSpace

Examples

Returns all user database files and free space information for the local host

Get-DbaDatabaseSpace -SqlInstance localhost

Returns all user database files and free space information for the local host. Filters the output object by any files that have a percent used of greater than 80%.

Get-DbaDatabaseSpace -SqlInstance localhost | Where-Object {$_.PercentUsed -gt 80}

Returns all user database files and free space information for the localhost and localhost\namedinstance SQL Server instances. Processes data via the pipeline.

‘localhost’,’localhost\namedinstance’ | Get-DbaDatabaseSpace

Returns database files and free space information for the db1 and db2 on localhost.

Get-DbaDatabaseSpace -SqlInstance localhost -Database db1, db2

Author

This command was created by Michael Fal. You can find Michael on Twitter and his blog.