簡體   English   中英

Azure 自動化 - 使用 Azure 命令或 PowerShell 命令運行腳本

[英]Azure Automation - Run scripts using Azure commands or PowerShell commands

我希望將生產工作移植到 Azure 自動化中。 目標是通過保存在該域中所有計算機上的共享驅動器中的腳本來安排維護。 使用 Azure,我可以使用 Invoke-AzVMRunCommand cmdlet 來完成此任務。 Powershell 還原生支持使用 Invoke-Command cmdlet 遠程運行腳本。

與另一個相比,使用一個 cmdlet 有什么特別的好處嗎? Invoke-Command 假設您與目標主機進行了開放式通信,但在我的情況下這是給定的。 使用 Invoke-Command 還有其他缺點嗎? Invoke-AzVMRunCommand 怎么樣?

From Azure portal if we want to run any powershell script inside an Azure VM, we use this Invoke-AzVMRunCommand cmdlet, there it will open the Powershell window to connect to the Azure VM from backend.

如果您需要使用來賓代理在 Azure VM 中運行腳本,建議使用運行命令選項。

您也可以直接從 Azure PowerShell、CLI 和 Cloud Shell 運行此命令。

Invoke-AzVMRunCommand -ResourceGroupName '<myResourceGroup>' -Name '<myVMName>' -CommandId 'RunPowerShellScript' -ScriptPath '<pathToScript>' -Parameter @{"arg1" = "var1";"arg2" = "var2"}

在此處輸入圖像描述

對於Invoke-AzVMRunCommand cmdlet ,我們需要在-ScriptPath參數中傳遞腳本,因此腳本文件必須位於運行 cmdlet 的位置。 無論您在哪里運行腳本,您都需要在那里有可用的腳本。

限制

要運行此命令,需要以下權限Microsoft.Compute/virtualMachines/runCommand/action 虛擬機貢獻者角色和更高級別將具有此功能。

Invoke-command cmdlet 僅用於調用任何 RestAPI 或使用 PowerShell 的操作。

請參閱此文檔以了解 Invoke 命令。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM