我有一个Windows Azure VM,需要执行“%windir%\ system32 \ sysprep”,然后从我的本地计算机通过Powershell从管理模式执行“ sysprep / generalize”。我该怎么办?
根据您的要求,据我所知,您可以使用PowerShell脚本来实现它。首先,您可以看一下Sysprep,它可以在PowerShell命令C:\WINDOWS\system32\sysprep\sysprep.exe /generalize /shutdown /oobe
中运行。将此命令放在脚本中,然后可以使用两种方法从本地计算机在VM中运行此脚本。一种是使用Invoke命令。
在Azure CLI中:
az vm run-command invoke --command-id RunPowerShellScript -g group_name -n vm_name --scripts @script.ps1
在PowerShell中:
Invoke-AzVMRunCommand -ResourceGroupName 'rgname' -VMName 'vmname' -CommandId 'RunPowerShellScript' -ScriptPath 'sample.ps1'
另一个是使用VM扩展名。这有点复杂。您可以看一下Azure PowerShell命令Set-AzVMCustomScriptExtension
。