我可以 运行 从 Azure DevOps 到 Azure 中的虚拟机的 powershell 命令吗?

Can I run powershell commands from Azure DevOps to vm's in Azure?

我如何在不使用 winrm 或 pssession 的情况下对 Azure 中的 Windows 2016 虚拟机 运行 PowerShell 命令,而我必须 install\configure 自签名证书?

有谁知道

如果您想执行 PowerShell,最好使用 Azure 自动化帐户而不是 Azure DevOps。

阅读 this 如何创建自动化帐户。

请参阅here如何使用 PowerShell 在 Azure 自动化中创建 Runbook。

如果您不需要经常 运行 一个命令,您可以简单地 运行 使用 运行 command,请看截图

如果我对你的查询的理解正确,你想 运行 Azure VM 上的 PowerShell 命令

  • 在这种情况下,Azure DevOps 服务将不知道将请求定向到哪里,因此开箱即用是不可能的。
  • 但是你可以做的是,你可以在这台机器上设置一个自托管代理(只要它连接到互联网)。
  • 然后您可以 运行 自托管代理上的任务,并选择 运行 powershell 任务。 (这可能需要您将防火墙上的一些 devops 范围列入白名单)。

除此之外,还有多种方法可以在 Azure VM 上 运行 命令和脚本,具体取决于您需要实施的设计。

您可以使用 Azure 门户在 Azure 门户中使用虚拟机 blade 在 VM 上执行预定义的自定义 PowerShell 命令。

另请查看这些文档以获取更多参考:

Run Powershell Cmds

Run Cmd

Can I run powershell commands from Azure DevOps to vm's in Azure?

Run PowerShell scripts in your Windows VM by using Run Command 提供了两个可能的方向:

1.Azure CLI way:

您可以在 azure devops 管道中使用 Azure CLI task 到 运行 az vm start az vm run-command invoke 命令。 az vm start 将启动虚拟机,然后第二个命令将 运行 PS 命令。

2.Powershell way:

您可以使用 Azure Powershell task in azure devops pipeline to run Start-AzVM and Invoke-AzVMRunCommand 命令。

注: 即使在 Web 门户中启动 VM 也需要几秒钟,因此建议这两个命令(Start VMRun PS)之间的间隔为 10~15 秒。例如: 试试 Start-Sleep -s 15.