Azure 自动化 Powersell Runbook 失败:“Invoke-Sqlcmd"未被识别为 cmdlet 的名称 [英] Azure Automation Powersell Runbook fails: 'Invoke-Sqlcmd' is not recognized as the name of a cmdlet

查看:57
本文介绍了Azure 自动化 Powersell Runbook 失败:“Invoke-Sqlcmd"未被识别为 cmdlet 的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这是我的操作手册:

$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写输出 $SQLOutput

结果如下:

希望这会有所帮助.

I have done all the steps of the following tutorial to have a runbook for automating index and statistic maintenance:

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

I was able to complete all the tutorial without errors, but when I execute the runbook, it returns me an error:

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

What can I do? I use SQL Server with Azure. Specifically, Azure SQL Database with pricing/model tier "S4 Standard (200 DTUs)".

解决方案

Follow that blog, I reproduced your error.

You can deploy sqlserver module via this page:

Here is my runbook:

$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

Here is the result:

Hope this helps.

这篇关于Azure 自动化 Powersell Runbook 失败:“Invoke-Sqlcmd"未被识别为 cmdlet 的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆