使用 Azure Windows VM 运行 PowerSell 脚本的自定义数据

kem*_*ety 6 powershell azure

我正在尝试在 Azure 云中配置 Windows VM 期间下载并安装 exe。我不想使用自定义脚本扩展,但我想使用“自定义数据”。我在 Azure 文档中找不到任何可靠的示例。

在AWS中,我找到了足够的资源,我可以开发下面的PowerShell脚本并将其添加到用户数据中,但这在Azure上不起作用,我尝试了不同的变体,但没有成功。以前有人这样做过吗?有没有这方面明确的文档?我读到 Azure 使用 Cloud-init,但同样,没有关于如何在 Windows 计算机上使用 Cloud-init 执行此操作的明确示例,所有示例均适用于 Linux。

<powershell>
start-transcript
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest 'https://www.domain-name.com/filename.exe' -OutFile C:\filename.exe
C:\filename.exe --quiet
</powershell>
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激。

pij*_*olu 6

您可以将数据注入到 Azure 上的 Windows 虚拟机中,但不幸的是您无法使用自定义数据或云初始化来执行它。仅 Ubuntu 映像支持使用 cloud init 执行自定义数据。

来源:https ://azure.microsoft.com/es-es/blog/custom-data-and-cloud-init-on-windows-azure/

要在配置后执行脚本,这取决于您配置虚拟机的方式。

  1. 在 ARM 模板中,您可以使用自定义脚本扩展:https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-windows
  2. az vm run-command使用 Azure CLI,您可以使用如下方式执行脚本:
az vm run-command invoke --command-id RunPowerShellScript --name win-vm -g my-resource-group  \
   --scripts 'param([string]$arg1)' \
   'Write-Host Hello' \
   --parameters 'arg1=kemety'
Run Code Online (Sandbox Code Playgroud)

来源: https: //learn.microsoft.com/en-us/cli/azure/vm/run-command? view=azure-cli-latest