Author | Garry Bargsley (@gbargsley), blog.garrybargsley.com , Klaas Vandenberghe (@PowerDbaKlaas) , Simone Bizzotto (@niphlod) |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Get-DbaDatabase on GitHub.
Want to see the Bill Of Health for this command? Check out Get-DbaDatabase.
Gets SQL Database information for each database that is present on the target instance(s) of SQL Server.
The Get-DbaDatabase command gets SQL database information for each database that is present on the target instance(s) of
SQL Server. If the name of the database is provided, the command will return only the specific database information.
Get-DbaDatabase
[-SqlInstance] <DbaInstanceParameter[]>
[[-SqlCredential] <PSCredential>]
[[-Database] <String[]>]
[[-ExcludeDatabase] <String[]>]
[-ExcludeUser]
[-ExcludeSystem]
[[-Owner] <String[]>]
[-Encrypted]
[[-Status] <String[]>]
[[-Access] <String>]
[[-RecoveryModel] <String[]>]
[-NoFullBackup]
[[-NoFullBackupSince] <DateTime>]
[-NoLogBackup]
[[-NoLogBackupSince] <DateTime>]
[-EnableException]
[-IncludeLastUsed]
[-OnlyAccessible]
[<CommonParameters>]
PS C:\> Get-DbaDatabase -SqlInstance localhost
Returns all databases on the local default SQL Server instance.
PS C:\> Get-DbaDatabase -SqlInstance localhost -ExcludeUser
Returns only the system databases on the local default SQL Server instance.
PS C:\> Get-DbaDatabase -SqlInstance localhost -ExcludeSystem
Returns only the user databases on the local default SQL Server instance.
PS C:\> 'localhost','sql2016' | Get-DbaDatabase
Returns databases on multiple instances piped into the function.
PS C:\> Get-DbaDatabase -SqlInstance SQL1\SQLExpress -RecoveryModel full,Simple
Returns only the user databases in Full or Simple recovery model from SQL Server instance SQL1\SQLExpress.
PS C:\> Get-DbaDatabase -SqlInstance SQL1\SQLExpress -Status Normal
Returns only the user databases with status 'normal' from SQL Server instance SQL1\SQLExpress.
PS C:\> Get-DbaDatabase -SqlInstance SQL1\SQLExpress -IncludeLastUsed
Returns the databases from SQL Server instance SQL1\SQLExpress and includes the last used information
from the sys.dm_db_index_usage_stats DMV.
PS C:\> Get-DbaDatabase -SqlInstance SQL1\SQLExpress,SQL2 -ExcludeDatabase model,master
Returns all databases except master and model from SQL Server instances SQL1\SQLExpress and SQL2.
PS C:\> Get-DbaDatabase -SqlInstance SQL1\SQLExpress,SQL2 -Encrypted
Returns only databases using TDE from SQL Server instances SQL1\SQLExpress and SQL2.
PS C:\> Get-DbaDatabase -SqlInstance SQL1\SQLExpress,SQL2 -Access ReadOnly
Returns only read only databases from SQL Server instances SQL1\SQLExpress and SQL2.
PS C:\> Get-DbaDatabase -SqlInstance SQL2,SQL3 -Database OneDB,OtherDB
Returns databases 'OneDb' and 'OtherDB' from SQL Server instances SQL2 and SQL3 if databases by those names exist on those instances.
The target SQL Server instance or instances.
Alias | |
Required | True |
Pipeline | true (ByValue) |
Default Value |
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies one or more database(s) to process. If unspecified, all databases will be processed.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies one or more database(s) to exclude from processing.
Alias | |
Required | False |
Pipeline | false |
Default Value |
If this switch is enabled, only databases which are not User databases will be processed.
This parameter cannot be used with -ExcludeSystem.
Alias | SystemDbOnly,NoUserDb,ExcludeAllUserDb |
Required | False |
Pipeline | false |
Default Value | False |
If this switch is enabled, only databases which are not System databases will be processed.
This parameter cannot be used with -ExcludeUser.
Alias | UserDbOnly,NoSystemDb,ExcludeAllSystemDb |
Required | False |
Pipeline | false |
Default Value | False |
Specifies one or more database owners. Only databases owned by the listed owner(s) will be returned.
Alias | |
Required | False |
Pipeline | false |
Default Value |
If this switch is enabled, only databases which have Transparent Data Encryption (TDE) enabled will be returned.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Specifies one or more database statuses to filter on. Only databases in the status(es) listed will be returned. Valid options for this parameter are 'EmergencyMode', 'Normal', 'Offline',
'Recovering', 'RecoveryPending', 'Restoring', 'Standby', and 'Suspect'.
Alias | |
Required | False |
Pipeline | false |
Default Value | @('EmergencyMode', 'Normal', 'Offline', 'Recovering', 'RecoveryPending', 'Restoring', 'Standby', 'Suspect') |
Accepted Values | EmergencyMode,Normal,Offline,Recovering,RecoveryPending,Restoring,Standby,Suspect |
Filters databases returned by their access type. Valid options for this parameter are 'ReadOnly' and 'ReadWrite'. If omitted, no filtering is performed.
Alias | |
Required | False |
Pipeline | false |
Default Value | |
Accepted Values | ReadOnly,ReadWrite |
Filters databases returned by their recovery model. Valid options for this parameter are 'Full', 'Simple', and 'BulkLogged'.
Alias | |
Required | False |
Pipeline | false |
Default Value | @('Full', 'Simple', 'BulkLogged') |
Accepted Values | Full,Simple,BulkLogged |
If this switch is enabled, only databases without a full backup recorded by SQL Server will be returned. This will also indicate which of these databases only have CopyOnly full backups.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Only databases which haven't had a full backup since the specified DateTime will be returned.
Alias | |
Required | False |
Pipeline | false |
Default Value |
If this switch is enabled, only databases without a log backup recorded by SQL Server will be returned.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Only databases which haven't had a log backup since the specified DateTime will be returned.
Alias | |
Required | False |
Pipeline | false |
Default Value |
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
If this switch is enabled, the last used read & write times for each database will be returned. This data is retrieved from sys.dm_db_index_usage_stats which is reset when SQL Server is restarted.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
If this switch is enabled, only accessible databases are returned (huge speedup in SMO enumeration)
Alias | |
Required | False |
Pipeline | false |
Default Value | False |