Connect to SQL server instance with credentials

Welcome Forums General PowerShell Q&A Connect to SQL server instance with credentials

Viewing 2 reply threads
  • Author
    Posts
    • #262049
      Participant
      Topics: 1
      Replies: 1
      Points: -30
      Rank: Member

      Hi Guys. i have couple of queries with PS + SQL. I have installed SQLserver module for my implementation.
      Case1 (Machine in domain): When i tried running Read-SqlTableData -ServerInstance $Instance -DatabaseName $Database -TableName $Table -SchemaName “dbo” it worked fine. But when i tried with credential Read-SqlTableData -ServerInstance $Instance -DatabaseName $Database -TableName $Table -SchemaName “dbo” -Credential Get-Credential it fails to connect. I am passing the Windows credential with which i have logged in. Could you help me understand why this is failing?
      Case 2 (Machine in workgroup) – In this case how to access SQL server which is in domain using SQL authentication through PS?

    • #262796
      Participant
      Topics: 8
      Replies: 16
      Points: 74
      Rank: Member

      -Credential parameter works with SQL authenication in SqlServer module. If you’re attempting to pass with different windows credentials, it fails.

      You may want to check other opensource powershell modules like dbatools which accepts both Windows + Sql auth credentials

      • This reply was modified 2 weeks ago by Harsha.
    • #264440
      Participant
      Topics: 1
      Replies: 1
      Points: -30
      Rank: Member

      Hi, Thanks for the reply. I was able to fix it. For some strange reason it wasnt working when i was running from ISE.

      I have another query. When i run : Get-SqlDatabase -ServerInstance $Instance -Credential $cred

      I am only able to see master and tempdb databases. Actually its not displaying my database ie,”CDW”. I am able to connect to “CDW” database from Microsoft SQL server management studio with the same $cred credentials. Could you tell me why i am not able to see database other than master and tempdb. Is it is because of access issue could you tell me what privilege is required.

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