简体   繁体   English

Azure Runbook 自动化 - Invoke-AzureRmVMRunCommand 错误

[英]Azure runbook automation - Invoke-AzureRmVMRunCommand error

I have an Azure runbook that runs on schedule.我有一个按计划运行的 Azure 运行手册。 Its in powershell and this runbook starts a VM and executes a script on the VM started.它在 powershell 中,此运行手册启动 VM 并在启动的 VM 上执行脚本。 How I achieve this is我是如何实现这一目标的

1) Store the script to be run on the VM in a storage account 2) Run powershell runbook 3) Powershell runbook uses wget command to copy the script from step 1 4) Invoke-AzureRmVMRunCommand in the Azure automation powershell commands as shown below 1) Store the script to be run on the VM in a storage account 2) Run powershell runbook 3) Powershell runbook uses wget command to copy the script from step 1 4) Invoke-AzureRmVMRunCommand in the Azure automation powershell commands as shown below

wget "https://utilitystorageaccnt.blob.core.windows.net/utilitycontainer/token" -outfile ((Get-Location).path + "\Reporting Copy.ps1") -UseBasicParsing

Invoke-AzureRmVMRunCommand -ResourceGroupName $ResourceGroupName -VMName $VmName -CommandId 'RunPowerShellScript' -ScriptPath ((Get-Location).path + '\Reporting Copy.ps1') -ErrorVariable result

Please not that the above two commands are in the powershell runbook script and not the actual script that is run on the VM.请注意,上述两个命令位于 powershell 运行手册脚本中,而不是在 VM 上运行的实际脚本中。

Facing two issues面临两个问题

1) When this script Reporting Copy.ps1 runs standalone on the VM, then it works properly and it has no issues. 1) 当这个脚本 Reporting Copy.ps1 在虚拟机上独立运行时,它可以正常工作并且没有问题。 When it is run using the runbook, I get these errors in the log file on the target vm.当它使用 runbook 运行时,我在目标 vm 上的日志文件中得到这些错误。

"New-AzStorageContext: The term 'New-AzStorageContext' 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." “New-AzStorageContext:术语 'New-AzStorageContext' 未被识别为 cmdlet、function、脚本文件或可运行程序的名称。请检查名称的拼写,或者如果包含路径,请验证路径是否为更正,然后再试一次。”

2) Even after this error occurs, it doesnt terminate and runs in loops. 2) 即使发生此错误,它也不会终止并循环运行。 This script does a copy operation and it keeps looping until all the copy is complete.该脚本执行复制操作,并不断循环,直到所有复制完成。 I can handle code to terminate but I would like to know how to force terminate a runbook.我可以处理要终止的代码,但我想知道如何强制终止运行手册。 I tried to stop the VM for even a hour and it resumes the copy operation.我试图停止虚拟机甚至一个小时,它会恢复复制操作。 The runbook status in Azure shows as completed. Azure 中的运行手册状态显示为已完成。 There are two python processes that show in explorer and terminating them doesn't work either.有两个 python 进程显示在资源管理器中,终止它们也不起作用。

Any help or hint is appreciated.任何帮助或提示表示赞赏。

Thanks.谢谢。

Look like you did not imported Az PowerShell module into our Automation Account.看起来您没有将 Az PowerShell 模块导入我们的自动化帐户。

Please, follow this tutorial: Az module support in Azure Automation请按照本教程进行操作: Azure 自动化中的 Az 模块支持

Try to use only Az module and not AzureRM尝试仅使用 Az 模块而不是 AzureRM

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 azure 自动化上执行 Invoke-AzureRmVMRunCommand 的问题 - Issue on executing Invoke-AzureRmVMRunCommand on azure automation Windows VM的Invoke-AzureRMVMRunCommand - Invoke-AzureRMVMRunCommand for Windows VM Azure Invoke-AzureRmVMRunCommand - 运行命令扩展执行正在进行中 - Azure Invoke-AzureRmVMRunCommand - Run command extension execution is in progress Invoke-AzureRmVMRunCommand 参数传递突然失败 - Invoke-AzureRmVMRunCommand parameter passing suddenly fails 在虚拟机上运行命令失败并阻止其他“Invoke-AzureRmVMRunCommand” - Run Command on Virtual Machine failing & preventing other 'Invoke-AzureRmVMRunCommand' 在 Invoke-AzureRmVMRunCommand 参数 hash 表中传递数组不起作用 - Passing an array in an Invoke-AzureRmVMRunCommand parameter hash table not working 如何获取Invoke-AzureRmVMRunCommand命令的输出流? - How to get output stream for Invoke-AzureRmVMRunCommand command? 在Powershell脚本中运行时,Invoke-AzureRmVMRunCommand命令显示错误的输出 - Invoke-AzureRmVMRunCommand command displaying wrong output when run in powershell script Azure Runbook 抛出错误:Invoke-ProcessASDatabase - Azure Runbook throwing error: Invoke-ProcessASDatabase Azure自动化:Runbook失败 - Azure automation: runbook is failing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM