commands

^

Rename-DbaLogin

Author Mitchell Hamann (@SirCaptainMitch)
Availability Windows, Linux, macOS

 

Synopsis

Rename-DbaLogin will rename login and database mapping for a specified login.

Description

There are times where you might want to rename a login that was copied down, or if the name is not descriptive for what it does.

It can be a pain to update all of the mappings for a specific user, this does it for you.

Syntax

Rename-DbaLogin
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [-Login] <String>
    [-NewLogin] <String>
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Rename-DbaLogin -SqlInstance localhost -Login DbaToolsUser -NewLogin captain

SQL Login Example

Example: 2
PS C:\> Rename-DbaLogin -SqlInstance localhost -Login domain\oldname -NewLogin domain\newname

Change the windowsuser login name.

Example: 3
PS C:\> Rename-DbaLogin -SqlInstance localhost -Login dbatoolsuser -NewLogin captain -WhatIf

WhatIf Example

Required Parameters

-SqlInstance

Source SQL Server.You must have sysadmin access and server version must be SQL Server version 2000 or greater.

Alias
Required True
Pipeline false
Default Value
-Login

The current Login on the server - this list is auto-populated from the server.

Alias
Required True
Pipeline false
Default Value
-NewLogin

The new Login that you wish to use. If it is a windows user login, then the SID must match.

Alias
Required True
Pipeline false
Default Value

Optional Parameters

-SqlCredential

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
-EnableException

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
-WhatIf

Shows what would happen if the command were to run. No actions are actually performed.

Alias wi
Required False
Pipeline false
Default Value
-Confirm

Prompts to confirm actions

Alias cf
Required False
Pipeline false
Default Value

 

Want to see the source code for this command? Check out Rename-DbaLogin on GitHub.
Want to see the Bill Of Health for this command? Check out Rename-DbaLogin.