The term 'Invoke-Sqlcmd' is not recognized as the name of a cmdlet in Azure Runbook

Vijay Kumar 2,016 Reputation points
2022-04-11T20:12:36.767+00:00

Hi,

Just created sample runbook in Azure to test azure SQL DB index maintenance.

Here is the code:`$AzureSQLServerName = "perfserver1sqlsrv-01.database.windows.net"
$AzureSQLDatabaseName = "empdatabase"

$AzureSQLServerName = $AzureSQLServerName + ".database.windows.net"
$Cred = Get-AutomationPSCredential -Name "SQLLogin"
$SQLOutput = $(Invoke-Sqlcmd -ServerInstance $AzureSQLServerName -Username $Cred.UserName -Password $Cred.GetNetworkCredential().Password -Database $AzureSQLDatabaseName -Query "exec [dbo].[AzureSQLMaintenance] @operation ='all' ,@LogToTable=1" -QueryTimeout 65535 -ConnectionTimeout 60 -Verbose) 4>&1

Write-Output $SQLOutput​

`
But when I run the book I am getting the below error:

System.Management.Automation.CommandNotFoundException: The term 'Invoke-Sqlcmd' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again

Azure SQL Database
0 comments No comments
{count} vote

0 additional answers

Sort by: Most helpful