Set‑SqlDscDatabaseOwner - dsccommunity/SqlServerDsc GitHub Wiki
Sets the owner of a database in a SQL Server Database Engine instance.
Set-SqlDscDatabaseOwner -ServerObject <Server> -Name <String> [-Refresh] -OwnerName <String>
[-DropExistingUser] [-Force] [-PassThru] [-WhatIf] [-Confirm]
[<CommonParameters>]
Set-SqlDscDatabaseOwner -DatabaseObject <Database> -OwnerName <String> [-DropExistingUser] [-Force] [-PassThru]
[-WhatIf] [-Confirm] [<CommonParameters>]
This command sets the owner of a database in a SQL Server Database Engine instance.
The owner must be a valid login on the SQL Server instance. The command uses the SetOwner() method on the SMO Database object to change the ownership.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
Set-SqlDscDatabaseOwner -ServerObject $serverObject -Name 'MyDatabase' -OwnerName 'sa'
Sets the owner of the database named MyDatabase to sa.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
Set-SqlDscDatabaseOwner -ServerObject $serverObject -Name 'MyDatabase' -OwnerName 'sa' -DropExistingUser
Sets the owner of the database named MyDatabase to sa, dropping any existing user account mapped to the sa login before changing the owner.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$databaseObject = $serverObject | Get-SqlDscDatabase -Name 'MyDatabase'
Set-SqlDscDatabaseOwner -DatabaseObject $databaseObject -OwnerName 'DOMAIN\SqlAdmin' -Force
Sets the owner of the database using a database object without prompting for confirmation.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
Set-SqlDscDatabaseOwner -ServerObject $serverObject -Name 'MyDatabase' -OwnerName 'sa' -PassThru
Sets the owner and returns the updated database object.
Specifies the database object to modify (from Get-SqlDscDatabase).
Type: Database
Parameter Sets: DatabaseObjectSet
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: FalseSpecifies whether to drop any existing database users mapped to the specified login before changing the owner. This is required if a non-dbo user account already exists for the login being set as the new owner.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies that the database owner should be modified without any confirmation.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the name of the database to modify.
Type: String
Parameter Sets: ServerObjectSet
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the name of the login that should be the owner of the database.
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies that the database object should be returned after modification.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies that the ServerObject's databases should be refreshed before trying to get the database object. This is helpful when databases could have been modified outside of the ServerObject, for example through T-SQL. But on instances with a large amount of databases it might be better to make sure the ServerObject is recent enough.
This parameter is only used when setting owner using ServerObject and Name parameters.
Type: SwitchParameter
Parameter Sets: ServerObjectSet
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies current server connection object.
Type: Server
Parameter Sets: ServerObjectSet
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalsePrompts you for confirmation before running the cmdlet.
Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseShows what would happen if the cmdlet runs. The cmdlet is not run.
Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseThis cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.