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


Get-DbaDatabaseState

Gets some common “states” on databases:

  • “RW” options : READ_ONLY or READ_WRITE
  • “Status” options : ONLINE, OFFLINE, EMERGENCY
  • “Access” options : SINGLE_USER, RESTRICTED_USER, MULTI_USER

Returns an object with SqlInstance, Database, RW, Status, Access

Screenshots

Examples

To get options for all databases of the sqlserver2014a instance

Get-DbaDatabaseState -SqlInstance sqlserver2014a

Gets options for both HR and Accounting database of the sqlserver2014a instance

Get-DbaDatabaseState -SqlInstance sqlserver2014a -Database HR, Accounting

To get options for all databases of the sqlserver2014a instance except HR

Get-DbaDatabaseState -SqlInstance sqlserver2014a -Exclude HR

To get options for all databases of sqlserver2014a and sqlserver2014b instances

‘sqlserver2014a’, ‘sqlserver2014b’ | Get-DbaDatabaseState

Author

This command was created by Simone Bizzotto. You can find Simone LinkedIn.

Get-Help

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

Source Code

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

Related commands