0

I have been trying so hard to use PowerShell command invoke-sqlcmd to run simple SQL queries on multiple SQL servers, where some are default instances servername and some are named instances ServerName\\InstanceName.

I have tried the following ways:
1: invoke-sqlcmd -ConnectionString $CN -Query $query ....
2: invoke-sqlcmd -Credential $adminSQL -Query $query ....
3: Start-Process powershell.exe -Credential $sysadminCred -ArgumentList "-NoExit", "-Command", "\$scriptBlock" ....

At first I was getting the typical error server not found....
Most of the time it was login failed because it keeps trying to use the WindowsAdmin account because I am logged in to server as WindowsAdmin, which has no DBA permission.

I hope you are successful or have done this already. Please share.

1
  • "Most of the time it was login failed because it keeps trying to use the WindowsAdmin account because I am logged in to server as WindowsAdmin, which has no DBA permission". How do you want to connect? Do you have a SQL Server login you would rather use? Commented Feb 12 at 14:46

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.