简体   繁体   English

Azure Runbook - 在远程 VM 上运行 Powershell

[英]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.

相关问题 Runbook 运行 Powershell 作为 azure 帐户 - Runbook Run Powershell as azure acccount 使用 runbook 编写 PowerShell 脚本来获取 VM 的快照: Run as Account: Azure - Write the PowerShell script using runbook to take the snapshot of the VM: Run as Account: Azure Azure VM中的远程Powershell - remote powershell in azure VM 如何连接到Azure Windows VM并使用PowerShell运行远程脚本? - How Connect to a Azure Windows VM and run a remote script with PowerShell? Sysprep Azure VM 与远程 PowerShell - Sysprep Azure VM with Remote PowerShell 如何在 Azure 自动化帐户 Python Runbook 或 Z531B84AD41B79AC07036 - How to run Azure CLI commands in Azure Automation Account Python Runbook or Powershell Runbook 用于修改/更新 Azure VM 标记值的代码在 Azure PowerShell Runbook 中不起作用 - Codes for modifying/updating Azure VM Tags value doesn't work in Azure PowerShell Runbook 如何对Azure Data Factory V2中的现有Azure VM运行远程命令(PowerShell / Bash)? - How to run a remote command (powershell/bash) against an existing Azure VM in Azure Data Factory V2? 将Azure PowerShell Cmdlet加载到远程VM - Load Azure PowerShell Cmdlets onto Remote VM 使用Azure Runbook监控Azure VM上的服务 - Monitoring Services on an Azure VM using an Azure Runbook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM