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

Vijay Kumar 2,036 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

Accepted answer
  1. Alberto Morillo 34,146 Reputation points MVP
    2022-04-11T20:28:09.857+00:00

    Please import SQL Module from here. You can also add the module using other methods described here.

    191978-image.png

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.