Author | Adam Lancaster, github.com/lancasteradam |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out New-DbaLinkedServerLogin on GitHub.
Want to see the Bill Of Health for this command? Check out New-DbaLinkedServerLogin.
Creates a new linked server login.
Creates a new linked server login. See the Microsoft documentation for sp_addlinkedsrvlogin for more details on the parameters.
New-DbaLinkedServerLogin
[[-SqlInstance] <DbaInstanceParameter[]>]
[[-SqlCredential] <PSCredential>]
[[-LinkedServer] <String[]>]
[[-LocalLogin] <String>]
[[-RemoteUser] <String>]
[[-RemoteUserPassword] <SecureString>]
[-Impersonate]
[[-InputObject] <LinkedServer[]>]
[-EnableException]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
PS C:\> New-DbaLinkedServerLogin -SqlInstance sql01 -LinkedServer linkedServer1 -LocalLogin localUser1 -RemoteUser remoteUser1 -RemoteUserPassword <password>
Creates a new linked server login and maps the local login testuser1 to the remote login testuser2. This linked server login is created on the sql01 instance for the linkedServer1 linked server.
NOTE: passwords are sent to the SQL Server instance in plain text. Check with your security administrator before using the command with the RemoteUserPassword parameter. View the documentation for
sp_addlinkedsrvlogin for more details.
PS C:\> New-DbaLinkedServerLogin -SqlInstance sql01 -LinkedServer linkedServer1 -Impersonate
Creates a mapping for all local logins on sql01 to connect using their own credentials to the linked server linkedServer1.
PS C:\> Get-DbaLinkedServer -SqlInstance sql01 -LinkedServer linkedServer1 | New-DbaLinkedServerLogin -LinkedServer linkedServer1 -LocalLogin testuser1 -RemoteUser testuser2 -RemoteUserPassword
Creates a new linked server login and maps the local login testuser1 to the remote login testuser2. This linked server login is created on the sql01 instance for the linkedServer1 linked server. The
linkedServer1 instance is passed in via pipeline.
NOTE: passwords are sent to the SQL Server instance in plain text. Check with your security administrator before using the command with the RemoteUserPassword parameter. View the documentation for
sp_addlinkedsrvlogin for more details.
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 name(s) of the linked server(s).
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies the local login name. This parameter is required in all scenarios.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies the remote login name.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies the remote login password as a secure string. NOTE: passwords are sent to the SQL Server instance in plain text. Check with your security administrator before using this parameter. View the
documentation for sp_addlinkedsrvlogin for more details.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies if the local login credentials should be used instead of the remote login credentials.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Allows piping from Get-DbaLinkedServer.
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 |