[英]Azure runbook - run Powershell on remote VM
Azure runbook. Azure 运行手册。
The question:问题:
How to run/call powershell scripts on remote Azure VM via runbook?如何通过 Runbook 在远程 Azure VM 上运行/调用 powershell 脚本? The script is placed on a remote VM.
该脚本放置在远程 VM 上。
There is no Azure AD, powershell has Az module installed.没有 Azure AD,powershell 安装了 Az 模块。
Thank you.谢谢你。
Have your Azure Automation runbook something like shown below.拥有如下所示的 Azure 自动化操作手册。 It will accomplish your requirement.
它会完成你的要求。
$ServicePrincipalConnection = Get-AutomationConnection -Name 'AzureRunAsConnection'
Add-AzAccount -ServicePrincipal -TenantId $ServicePrincipalConnection.TenantId -ApplicationId $ServicePrincipalConnection.ApplicationId -CertificateThumbprint $ServicePrincipalConnection.CertificateThumbprint
$rgname ="rrrrrrrrrrrrrr"
$vmname ="vvvvvvvvvvvvvv"
$ScriptToRun = "ssssssssssssss"
Out-File -InputObject $ScriptToRun -FilePath ScriptToRun.ps1
Invoke-AzVMRunCommand -ResourceGroupName $rgname -Name $vmname -CommandId 'RunPowerShellScript' -ScriptPath ScriptToRun.ps1
Remove-Item -Path ScriptToRun.ps1
Note: Before you run your runbook, make sure you update "rrrrrrrrrrrrrr" with your resource group name, "vvvvvvvvvvvvvv" with your VM name and "ssssssssssssss" with the path of the script along with script name注意:在运行 Runbook 之前,请确保使用资源组名称更新“rrrrrrrrrrrrrr”,使用 VM 名称更新“vvvvvvvvvvvvvv”,使用脚本路径和脚本名称更新“sssssssssssssss”
For reference, you may refer the source from here .作为参考,您可以参考此处的来源。
Hope this helps!!希望这可以帮助!! Cheers!!
干杯!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.