【发布时间】:2020-12-31 16:23:42
【问题描述】:
我不想创建将启动特定(或参数控制)VM,然后在 VM 上运行脚本(本地或从 blob 存储)的 Runbook。
我检查了很多文档,但到目前为止还没有成功。
到目前为止我在同一个资源组下得到了什么:
已创建虚拟机
已创建自动化帐户,包括。运行方式帐号
Azure 自动化解决方案 (OMS)
自动化帐户下的凭据(我自己的帐户)
使用了几个 Runbook 库和其他使用函数的代码示例,例如 启动-AzureVM ... 调用命令 ...
你们当中有没有人可以根据所使用的方法对需要什么的指南进行采样?
VM 启动部分正在工作,但我无法让登录 + 执行脚本工作!
我不是一个熟练的开发人员,我什至对在 Azure 中的脚本语言之间进行选择感到怀疑。
我们将不胜感激。
谢谢, 汤姆
调用命令
调用-AzureRmVMRunCommand
设置-AzureRmVMCustomScriptExtension
New-SSHSession + Invoke-SSHCommand
代码取自例如画廊“Connect-AzureVM”
【问题讨论】:
-
关于在虚拟机上运行脚本(本地或从blob存储),本地是否意味着脚本文件在虚拟机上?
-
是的,要么存储在 VM 上,要么存储在容器中。主要目标是运行让脚本在成功登录后运行:-)
-
以下脚本运行并返回错误:Invoke-AzureRmVMRunCommand:找不到文件“C:\home\tdj\test.sh”。在 line:6 char:1 + Invoke-AzureRmVMRunCommand -ResourceGroupName 'SAPBASIS' -Name 'sles1 ...
-
PS 脚本:$conn = Get-AutomationConnection -Name AzureRunAsConnection Login-AzureRmAccount -ServicePrincipal -Tenant $conn.TenantID ` -ApplicationId $conn.ApplicationID -CertificateThumbprint $conn.CertificateThumbprint Start-AzureRmVM -Name ' VM' -ResourceGroupName 'RG' Invoke-AzureRmVMRunCommand -ResourceGroupName 'RG' -Name 'VM' -CommandId 'RunPowerShellScript' -ScriptPath '/home/user/test.sh' -Parameter @{"arg1" = "var1";" arg2" = "var2"}
-
你可能误解了Invoke-AzureRmVMRunCommand的参数-ScriptPath,根据我的测试,-ScriptPath是你启动命令的路径,而不是在远程机器上。