Author | Adam Lancaster, github.com/lancasteradam |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Get-DbaDbSchema on GitHub.
Want to see the Bill Of Health for this command? Check out Get-DbaDbSchema.
Finds the database schema SMO object(s) based on the given filter params.
Finds the database schema SMO object(s) based on the given filter params.
Get-DbaDbSchema
[[-SqlInstance] <DbaInstanceParameter[]>]
[[-SqlCredential] <PSCredential>]
[[-Database] <String[]>]
[[-Schema] <String[]>]
[[-SchemaOwner] <String[]>]
[-IncludeSystemDatabases]
[-IncludeSystemSchemas]
[[-InputObject] <Database[]>]
[-EnableException]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
PS C:\> Get-DbaDbSchema -SqlInstance localhost
Gets all non-system database schemas from all user databases on the localhost instance. Note: the dbo schema is a system schema and won't be included in the output from this example. To include the
dbo schema specify -IncludeSystemSchemas
PS C:\> Get-DbaDbSchema -SqlInstance localhost -Schema dbo -IncludeSystemSchemas
Returns the dbo schema from the databases on the localhost instance.
PS C:\> Get-DbaDbSchema -SqlInstance localhost -IncludeSystemDatabases -IncludeSystemSchemas
Gets all database schemas from all databases on the localhost instance.
PS C:\> Get-DbaDbSchema -SqlInstance localhost -Schema TestSchema
Finds and returns the TestSchema schema from the localhost instance.
PS C:\> Get-DbaDbSchema -SqlInstance localhost -SchemaOwner DBUser1
Finds and returns the schemas owned by DBUser1 from the localhost instance.
PS C:\> Get-DbaDbSchema -SqlInstance localhost -Database TestDB -SchemaOwner DBUser1
Finds and returns the schemas owned by DBUser1 in the TestDB database from the localhost instance.
PS C:\> $schema = Get-DbaDbSchema -SqlInstance localhost -Database TestDB -Schema TestSchema
PS C:\> $schema.Owner = DBUser2
PS C:\> $schema.Alter()
Finds the TestSchema in the TestDB on the localhost instance and then changes the schema owner to DBUser2
PS C:\> $schema = Get-DbaDbSchema -SqlInstance localhost -Database TestDB -Schema TestSchema
PS C:\> $schema.Drop()
Finds the TestSchema in the TestDB on the localhost instance and then drops it. Note: to drop a schema all objects must be transferred to another schema or dropped.
PS C:\> $db = Get-DbaDatabase -SqlInstance localhost -Database TestDB
PS C:\> $schema = $db | Get-DbaDbSchema -Schema TestSchema
Finds the TestSchema in the TestDB which is passed via pipeline into the Get-DbaDbSchema command.
The target SQL Server instance or instances. This can be a collection and receive pipeline input to allow the function
to be executed against multiple SQL Server instances.
Alias | |
Required | False |
Pipeline | false |
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 |
The target database(s).
Alias | |
Required | False |
Pipeline | false |
Default Value |
The name(s) of the schema(s)
Alias | |
Required | False |
Pipeline | false |
Default Value |
The name(s) of the database user(s) that own(s) the schema(s).
Alias | |
Required | False |
Pipeline | false |
Default Value |
Include the system databases.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Include the system schemas.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Allows piping from Get-DbaDatabase.
Alias | |
Required | False |
Pipeline | true (ByValue) |
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 |
Shows what would happen if the command were to run. No actions are actually performed.
Alias | wi |
Required | False |
Pipeline | false |
Default Value |
Prompts you for confirmation before executing any changing operations within the command.
Alias | cf |
Required | False |
Pipeline | false |
Default Value |