Set-sqmDatabaseOwner
ConfigurationsqmSQLTool v1.8.2+ · Database Admin⚠ Alters Ownership ✓ Validation
Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -SqlInstance | string | Optional | $env:COMPUTERNAME | Target SQL Server instance. |
| -SqlCredential | PSCredential | Optional | , | Credentials for the connection. |
| -Database | string[] | Optional | @() | Target databases (name or wildcard pattern). |
| -ContinueOnError | switch | Switch | $false | Continue to next database on error. |
| -EnableException | switch | Switch | $false | Re-throw exceptions immediately. |
| -WhatIf / -Confirm | switch | Optional | , | ShouldProcess (ConfirmImpact: Medium) guards ownership change. |
| -ExcludeDatabase | string[] | Optional | @() | Databases to exclude. Wildcards allowed. |
| -Force | switch | Switch | $false | Also process databases that already have the correct owner (forces re-assignment). |
| -IncludeSystemDatabases | switch | Switch | $false | Also include system databases (master, model, msdb). Default: $false. tempdb is always excluded. |
| -OutputPath | string | Optional | , | Directory for the change log. Default: from module configuration. |
| -OwnerLogin | string | Optional | , | Login to set as the new owner. Default: sa account (automatically determined via SID 0x01, regardless of whether it has been renamed). |
Execution Flow
Examples
Change single database owner
Set-sqmDatabaseOwner -SqlInstance "SQL01" -Database "MyDB" -OwnerLogin "domain\admin"
Change owner for multiple databases with -WhatIf
Set-sqmDatabaseOwner -SqlInstance "SQL01" -Database "Prod*" -OwnerLogin "sqlsvc" -WhatIf