Dave
Dave

Reputation: 883

Windows password does not work for Powershell Credential Request

I am aware I can set up Powershell credentials Get-Credential for my own scripts. But when I use the following command Get a SQL Server instance on a computer in a PS terminal:

Get-SqlInstance -Credential laptop-ql9k5dk6\david -ServerInstance "laptop-ql9k5dk6\sqlexpress2"

I expect that I am going to be asked for my Windows password.

Here is my thinking:

Logging in to my SQL Server instance (laptop-ql9k5dk6\david) via MS SQL Server Management Studio (using Windows Authentication) uses my already logged on status. Otherwise I would need my Windows password.

Since my script is asking for a password for laptop-ql9k5dk6\david; I think it must be my Windows password?

So. Why does my Windows Password fail when my PowerShell one-liner (shown above) asks me for a password?

PowerShell credential request
Enter your credentials.
Password for user laptop-ql9k5dk6\david: **************

Get-SqlInstance: Failed to connect to server laptop-ql9k5dk6\sqlexpress2.

On MSSM I can also login via SQL Login but for that the username is different from the Windows Authentication user above.

Note: My current Windows password is good. I use it regularly without making mistakes/leaving CAPs on etc.

Upvotes: 0

Views: 554

Answers (1)

rinat gadeev
rinat gadeev

Reputation: 142

$role = "sql"
$user = read-host "user for $role"
$pwd = read-host "password:" -AsSecureString
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $user, $pwd

Get-SqlInstance -Credential $cred -ServerInstance "laptop-ql9k5dk6\sqlexpress2"

perhaps the cmdlet does not support Integrated Security=true;

Upvotes: 1

Related Questions