Azure Runbook - 在远程虚拟机上运行 Powershell

标签 azure powershell azure-runbook runbook

Azure 运行手册。

问题:

如何通过 Runbook 在远程 Azure VM 上运行/调用 powershell 脚本?该脚本放置在远程虚拟机上。

没有 Azure AD,powershell 安装了 Az 模块。

谢谢。

最佳答案

让您的 Azure 自动化操作手册如下所示。它将满足您的要求。

$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

注意:在运行 Runbook 之前,请确保使用资源组名称更新“rrrrrrrrrrrrrr”,使用虚拟机名称更新“vvvvvvvvvvvvvv”,使用脚本路径和脚本名称更新“sssssssssssssss”

作为引用,您可以引用here的来源.

希望这有帮助!干杯!!

关于Azure Runbook - 在远程虚拟机上运行 Powershell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59982721/

相关文章:

azure - 从 Azure 中的 Linux 虚拟机备份文件

powershell - get-childitem 在格式之前截断名称、全名

windows - "Extend my Windows desktop onto this monitor"以编程方式

powershell - 获取广告商制作属性列表

azure - 自定义控制台应用程序可以在 Azure (PowerShell) Runbook 中执行吗?

azure - 使用电子邮件字段在 Azure AD 中批量创建用户

image - 使用 terraform 从自定义镜像创建 azure vm 错误

azure - 新-AzureDeployment : The remote server returned an error: (403) Forbidden

azure - 使用 Powershell 创建 Azure 存储帐户的 SFTP 本地用户

azure - 启动-AzVM : Cannot bind parameter 'DefaultProfile' when running an Azure runbook