Answered by:
Invoke-SqlCmd - Parameter not recognized - Credential

Question
-
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?Monday, February 3, 2020 11:49 PM
Answers
-
Thanks. It would seem that way, but:
PS C:\> Get-Command Invoke-SqlcmdCommandType Name Version Source
----------- ---- ------- ------
Cmdlet Invoke-Sqlcmd 21.1.18068 sqlServer- Marked as answer by CBS3 Tuesday, February 4, 2020 3:42 PM
Tuesday, February 4, 2020 3:17 PM
All replies
-
You clearly do not have the correct module installed.
get-command invoke-sqlcmd
Check.
\_(ツ)_/
Tuesday, February 4, 2020 2:36 AM -
Thanks. It would seem that way, but:
PS C:\> Get-Command Invoke-SqlcmdCommandType Name Version Source
----------- ---- ------- ------
Cmdlet Invoke-Sqlcmd 21.1.18068 sqlServer- Marked as answer by CBS3 Tuesday, February 4, 2020 3:42 PM
Tuesday, February 4, 2020 3:17 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
Tuesday, February 4, 2020 3:42 PM