I’ve got a script to create Linked Server connections, and add logins. But in “For a login not defined in the list above, connections will:” I’m unable to set the “Be made using this security context”.
This is what I’ve got so far, see below, and that creates the linked server and adds the login to “Local server login to remote server login mappings:” - but I want to have that login as the “Be made using this security context”.
$LinkedServerName = "LinkedServer" $lsvrLoginName = 'linkservers' $pwd = 'Passw0rd!' $SqlServer = "Server\Instance" $svr = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Server $SqlServer $lsvr = New-Object -TypeName Microsoft.SqlServer.Management.SMO.LinkedServer -argumentlist $svr,$LinkedServerName $lsvr.ProductName = "SQL Server" $lsvr.Create() $lsvrlogin = New-Object -TypeName Microsoft.SqlServer.Management.SMO.LinkedServerLogin $lsvrlogin.Parent = $lsvr $lsvrlogin.name = $lsvrLoginName $lsvrlogin.RemoteUser = $lsvrLoginName $lsvrlogin.SetRemotePassword($pwd); $lsvrlogin.Create()