commands

^

New-DbaLinkedServer

Author Adam Lancaster, github.com/lancasteradam
Availability Windows, Linux, macOS

 

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

Synopsis

Creates a new linked server.

Description

Creates a new linked server. See the Microsoft documentation for sp_addlinkedserver for more details on the parameters.

Syntax

New-DbaLinkedServer
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-SqlCredential] <PSCredential>]
    [[-LinkedServer] <String>]
    [[-ServerProduct] <String>]
    [[-Provider] <String>]
    [[-DataSource] <String>]
    [[-Location] <String>]
    [[-ProviderString] <String>]
    [[-Catalog] <String>]
    [[-SecurityContext] <String>]
    [[-SecurityContextRemoteUser] <String>]
    [[-SecurityContextRemoteUserPassword] <SecureString>]
    [[-InputObject] <Server[]>]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> New-DbaLinkedServer -SqlInstance sql01 -LinkedServer linkedServer1 -ServerProduct mssql -Provider sqlncli -DataSource sql02

Creates a new linked server named linkedServer1 on the sql01 instance. The link is via the SQL Native Client and is connected to the sql02 instance.

Example: 2
PS C:\> Connect-DbaInstance -SqlInstance sql01 | New-DbaLinkedServer -LinkedServer linkedServer1 -ServerProduct mssql -Provider sqlncli -DataSource sql02

Creates a new linked server named linkedServer1 on the sql01 instance. The link is via the SQL Native Client and is connected to the sql02 instance. The sql01 instance is passed in via pipeline.

Example: 3
PS C:\> New-DbaLinkedServer -SqlInstance sql01 -LinkedServer linkedServer1 -ServerProduct mssql -Provider sqlncli -DataSource sql02 -SecurityContext CurrentSecurityContext

Creates a new linked server named linkedServer1 on the sql01 instance. The link is via the SQL Native Client and is connected to the sql02 instance. Connections with logins that are not explicitly
mapped to the remote server will use the current login's security context.

Optional Parameters

-SqlInstance

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

The name of the linked server.

Alias
Required False
Pipeline false
Default Value
-ServerProduct

The product name of the data source.

Alias
Required False
Pipeline false
Default Value
-Provider

The unique ID of the provider.

Alias
Required False
Pipeline false
Default Value
-DataSource

The name of the data source.

Alias
Required False
Pipeline false
Default Value
-Location

The location of the database.

Alias
Required False
Pipeline false
Default Value
-ProviderString

The provider connection string.

Alias
Required False
Pipeline false
Default Value
-Catalog

The catalog or default database.

Alias
Required False
Pipeline false
Default Value
-SecurityContext

Specifies the security context option found on the SSMS Security tab of the linked server. This is a separate configuration from the mapping of a local login to a remote login. It specifies the connection behavior for a login that is not explicitly mapped. 'NoConnection' means that a connection will not be made. 'WithoutSecurityContext' means the connection will be made without using a security context. 'CurrentSecurityContext' means the connection will be made using the login's current security context. 'SpecifiedSecurityContext' means the specified username and password will be used. The default value is 'WithoutSecurityContext'. For more details see the Microsoft documentation for sp_addlinkedsrvlogin and also review the SSMS Security tab of the linked server.

Alias
Required False
Pipeline false
Default Value WithoutSecurityContext
Accepted Values NoConnection,WithoutSecurityContext,CurrentSecurityContext,SpecifiedSecurityContext
-SecurityContextRemoteUser

Specifies the remote login name. This param is used when SecurityContext is set to SpecifiedSecurityContext. To map a local login to a remote login use New-DbaLinkedServerLogin.

Alias
Required False
Pipeline false
Default Value
-SecurityContextRemoteUserPassword

Specifies the remote login password. This param is used when SecurityContext is set to SpecifiedSecurityContext. To map a local login to a remote login use New-DbaLinkedServerLogin. NOTE: passwords are sent to the SQL Server instance in plain text. Check with your security administrator before using this parameter.

Alias
Required False
Pipeline false
Default Value
-InputObject

Allows piping from Connect-DbaInstance.

Alias
Required False
Pipeline true (ByValue)
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 you for confirmation before executing any changing operations within the command.

Alias cf
Required False
Pipeline false
Default Value