Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, February 3, 2020 11:49 PM
I'm trying to get familiar with Invoke-SqlCmd so I can use alternate credentials to access the DB. When I use the -Credential parameter I get the error it is not recognized.
I am using the "SqlServer" module (21.1.18068), installed with -AllowClobber. Not using SqlPS. I saw a post that said the call had to be within a function... Seemed quirky, but I tried it anyway. No joy.
Here is a sample of the call:
Invoke-Sqlcmd -ServerInstance $Server `
-Database $Database `
-Query $Query `
-Credential $Cred `
-Verbose
All those variables are populated with appropriate values.
Any thoughts?
All replies (3)
Tuesday, February 4, 2020 3:17 PM ✅Answered
Thanks. It would seem that way, but:
PS C:\ Get-Command Invoke-Sqlcmd
CommandType Name Version Source
Cmdlet Invoke-Sqlcmd 21.1.18068 sqlServer
Tuesday, February 4, 2020 2:36 AM
You clearly do not have the correct module installed.
get-command invoke-sqlcmd
Check.
\(ツ)_/
Tuesday, February 4, 2020 3:42 PM
OK, I got one step further. I found SqlPS module in $PSModulePath and renamed it. Had to reboot to release the folder for rename. That allowed SqlServer module to load the right Invoke-SqlCmd command, even though it seemed to be reporting as loaded previously.
So, closing this question/post. I'll have a new one about credential use...
FullyQualifiedErrorId : ExecutionFailureException,Microsoft.SqlServer.Management.PowerShell.GetScriptCo
mmand