我有一个 Windows Azure VM,需要执行“%windir%\system32\sysprep”,然后通过 Powershell 从本地计算机的管理模式执行“sysprep/generalize”。我怎样才能做到这一点?
最佳答案
根据您的要求,据我所知您可以使用 PowerShell 脚本来实现它。首先,你可以看一下Sysprep ,它可以在 PowerShell 命令 C:\WINDOWS\system32\sysprep\sysprep.exe/generalize/shutdown/oobe
中运行。将此命令放入脚本中,然后您可以使用两种方式从本地计算机在虚拟机中运行此脚本。一种是使用 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
。
运行后输出:-
Value[0] :
Code : ComponentStatus/StdOut/succeeded
Level : Info
DisplayStatus : Provisioning succeeded
Message :
Value[1] :
Code : ComponentStatus/StdErr/succeeded
Level : Info
DisplayStatus : Provisioning succeeded
Message :
Status : Succeeded
Capacity : 0
Count : 0
关于azure - 如何使用 Powershell 从本地计算机在 Azure Windows 虚拟机 (VM) 中运行 "sysprep/generalize”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61954959/