Azure Automation Powersell Runbook 失败:'Invoke-Sqlcmd' 未被识别为 cmdlet 的名称

Azure Automation Powersell Runbook fails: 'Invoke-Sqlcmd' is not recognized as the name of a cmdlet

我已经完成了以下教程的所有步骤,获得了自动化索引和统计维护的操作手册:

https://blogs.msdn.microsoft.com/azuresqldbsupport/2018/01/15/automating-azure-sql-db-index-and-statistic-maintenance-using-azure-automation/

我能够顺利完成所有教程,但是当我执行 runbook 时,returns 我出错了:

Invoke-Sqlcmd : 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.
At line:6 char:16
+ $SQLOutput = $(Invoke-Sqlcmd -ServerInstance $AzureSQLServerName -Use ...
+ ~~~~~~~~~~~~~
+ CategoryInfo: ObjectNotFound: (Invoke-Sqlcmd:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

我能做什么?我在 Azure 中使用 SQL 服务器。具体来说,具有 pricing/model 层 "S4 Standard (200 DTUs)".

的 Azure SQL 数据库

关注那个博客,我重现了你的错误。

您可以通过此页面部署 sqlserver module

这是我的操作手册:

$AzureSQLServerName = "jasonsql"
$AzureSQLDatabaseName = "jasondatabase"

$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 "SELECT * FROM INFORMATION_SCHEMA.TABLES " -QueryTimeout 65535 -ConnectionTimeout 60 -Verbose) 4>&1

Write-Output $SQLOutput

结果如下:

希望对您有所帮助。