Default login for Linked Server connection

Welcome Forums General PowerShell Q&A Default login for Linked Server connection

Viewing 0 reply threads
  • Author
    Posts
    • #182550
      Participant
      Topics: 41
      Replies: 167
      Points: 574
      Helping Hand
      Rank: Major Contributor

      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()
      
      

       

Viewing 0 reply threads
  • You must be logged in to reply to this topic.