问题描述
获取错误
Getting Error
失败
行:37 char:34
+ ... s_Running = Get-AzureRMWebAPP -ResourceGroupName $ ResourcegroupName | ... ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
找不到'Get-AzureRMWebAPP'命令。如果将此命令定义为工作流,请确保在调用它的工作流之前定义它。如果它是一个旨在直接在Windows PowerShell中运行的命令(或在此系统上不可用),请将
放在InlineScript中:'InlineScript {Get-AzureRMWe
failed
At line:37 char:34
+ ... s_Running = Get-AzureRMWebAPP -ResourceGroupName $ResourcegroupName | ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cannot find the 'Get-AzureRMWebAPP' command. If this command is defined as a workflow, ensure it is defined before the workflow that calls it. If it is a command intended to run directly within Windows PowerShell (or is not available on this system), place it in an InlineScript: 'InlineScript { Get-AzureRMWe
尝试更新Runbook。
Tried Updating the runbook.
这是我的脚本
工作流程START_STOP_APP_SERVICE_BY_RESOURCE
{
#参数
Param(
[参数(强制= $) true)]
[bool] $ Stop,
[参数(强制= $ true)]
[string] $ CredentialAssetName,
[参数(强制= $ true)]
[string] $ ResourcegroupName
)
#此Runbook将用于向Azure进行身份验证的Automation Credential Asset的名称。
  $ CredentialAssetName = $ CredentialAssetName;
#从自动化资产商店获取具有上述名称的凭证
  $ Cred = Get-AutomationPSCredential -Name $ CredentialAssetName
  if(!$ Cred){
     抛出"找不到名为'$ {CredentialAssetName}'的自动凭证资产。确保您已在此自动化帐户中创建了一个。"
  }
$
  #Connect到您的Azure帐户
Add-AzureRmAccount - 凭证$ Cred
$ status ='已停止'
if($ Stop)
{
$ status ='Running'
}
#Get运行WebApps(website_Processings_Running)
$ website_Processings_Running = Get-AzureRMWebAPP -ResourceGroupName $ ResourcegroupName | where-object -FilterScript {$ _.state -eq $ status}
foreach -parallel($ website_Processing in $ website_Processings_Running)
{
if($ Stop)
{
$ result = Stop-AzureRmWebApp -ResourceGroupName $ ResourcegroupName -Name $ website_Processing.Name
if($ result)
{
写入输出" - $($ website_Processing.Name)成功关闭" b
}
其他
{
写入输出" + $($ website_Processing.Name)未成功关闭"
$
}
}
其他
{
$ result = Start-AzureRmWebApp -ResourceGroupName $ ResourcegroupName -Name $ website_Processing.Name
if($ result)
{
写入输出" - $($ website_Processing.Name)成功启动"
}
其他
{
写入输出" + $($ website_Processing.Name)未成功启动"
$
}
}
}
}
Workflow START_STOP_APP_SERVICE_BY_RESOURCE
{
# Parameters
Param(
[Parameter (Mandatory= $true)]
[bool]$Stop,
[Parameter (Mandatory= $true)]
[string]$CredentialAssetName,
[Parameter (Mandatory= $true)]
[string]$ResourcegroupName
)
#The name of the Automation Credential Asset this runbook will use to authenticate to Azure.
$CredentialAssetName = $CredentialAssetName;
#Get the credential with the above name from the Automation Asset store
$Cred = Get-AutomationPSCredential -Name $CredentialAssetName
if(!$Cred) {
Throw "Could not find an Automation Credential Asset named '${CredentialAssetName}'. Make sure you have created one in this Automation Account."
}
#Connect to your Azure Account
Add-AzureRmAccount -Credential $Cred
$status = 'Stopped'
if ($Stop)
{
$status = 'Running'
}
# Get Running WebApps (website_Processings_Running)
$website_Processings_Running = Get-AzureRMWebAPP -ResourceGroupName $ResourcegroupName | where-object -FilterScript{$_.state -eq $status }
foreach -parallel ($website_Processing In $website_Processings_Running)
{
if ($Stop)
{
$result = Stop-AzureRmWebApp -ResourceGroupName $ResourcegroupName -Name $website_Processing.Name
if($result)
{
Write-Output "- $($website_Processing.Name) shutdown successfully"
}
else
{
Write-Output "+ $($website_Processing.Name) did not shutdown successfully"
}
}
else
{
$result = Start-AzureRmWebApp -ResourceGroupName $ResourcegroupName -Name $website_Processing.Name
if($result)
{
Write-Output "- $($website_Processing.Name) start successfully"
}
else
{
Write-Output "+ $($website_Processing.Name) did not started successfully"
}
}
}
}
脚本
推荐答案
你能详细说明你的意思吗?来自Gallery Runbook" ?
Can you please elaborate on what you meant by "from Gallery Runbook" ?
我已成功复制并解决了该问题。您收到错误的原因是模块"AzureRM.Websites" (不需要使用cmdlet Get-AzureRMWebApp)不会从Modules gallery磁贴中导入。请导入模块"AzureRM.Websites"按照下面提到的流程
并尝试执行PowerShell工作流程Runbook。
I have reproduced and resolved the issue successfully. You are getting the error because the module "AzureRM.Websites" (which is required to use the cmdlet Get-AzureRMWebApp) is not imported from Modules gallery tile. Please import the module "AzureRM.Websites" by following the process mentioned below and try executing your PowerShell workflow runbook.
从库中导入模块的过程:
Process to import module from gallery:
转到Azure门户>自动化帐户>您的自定义帐户>模块库>输入"AzureRM.Websites"在搜索框中按住回车键>选择"AzureRM.Websites"来自搜索列表>点击"导入"。
Goto Azure portal > Automation Accounts > YOURAUTOMATIONACCOUNT > Modules gallery > Type "AzureRM.Websites" in search box and hit enter > select "AzureRM.Websites" from the search list > Click "Import".
希望这有帮助!! :)
Hope this helps!! :)
问候,
Krishna
这篇关于用于启动/停止Web应用程序的RunBook无法按预期从Gallery Runbook“无法找到'Get-AzureRMWebAPP'命令”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!