【问题标题】:Executing Remote Command via Powershell in Azure with no script在 Azure 中通过 Powershell 执行远程命令,无需脚本
【发布时间】:2020-10-23 17:50:05
【问题描述】:

我正在尝试使用 Powershell 设置 Azure VM,但我希望在不登录机器的情况下远程完成所有操作。我已经能够使用 New-AzVM 之类的命令启动 VM,但现在我需要运行特定的 powershell 命令,例如Enable-WindowsOptionalFeature -Online -FeatureName IIS-ManagementConsole

我可以看到您可以使用以下命令运行远程脚本,但由于这是一个全新的服务器,因此该框上没有要执行的脚本。

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

如何将脚本远程复制到服务器,这样我就可以使用上述命令,或者无需脚本文件即可运行命令。

【问题讨论】:

    标签: azure powershell


    【解决方案1】:

    您无需将脚本远程复制到 Azure VM。您可以在本地运行它。

    将 PowerShell 脚本保存为格式 .ps1 文件,然后在本地 PowerShell 上运行它,并通过参数 -ScriptPath 引用脚本的路径。

    Enable-WindowsOptionalFeature -Online -FeatureName IIS-ManagementConsole
    

    您也可以复制虚拟机上的脚本---运行命令---Azure门户上的RunPowerShellScript,参考this

    【讨论】:

      【解决方案2】:

      你需要看看 PowerShell Desired State Configuration (DSC) 的方向

      1. Here you can find general explanation for this technology
      2. Get started manual for DSC

      【讨论】:

        猜你喜欢
        • 2019-05-09
        • 1970-01-01
        • 2019-02-08
        • 1970-01-01
        • 2021-08-08
        • 1970-01-01
        • 2021-05-10
        • 2012-01-12
        • 1970-01-01
        相关资源
        最近更新 更多