如何使用Powershell从本地计算机在Azure Windows虚拟机(VM)中运行“ sysprep / generalize”?

问题描述 投票:0回答:1

我有一个Windows Azure VM,需要执行“%windir%\ system32 \ sysprep”,然后从我的本地计算机通过Powershell从管理模式执行“ sysprep / generalize”。我该怎么办?

azure powershell azure-powershell powershell-remoting azure-vm
1个回答
0
投票

根据您的要求,据我所知,您可以使用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

© www.soinside.com 2019 - 2024. All rights reserved.