如何使用 Powershell 从我的本地机器 运行 在 Azure Windows 虚拟机 (VM) 中“sysprep /generalize”?
How to run "sysprep /generalize” in Azure Windows Virtual Machine (VM) from my local machine using Powershell?
我有一个 windows Azure 虚拟机,需要执行“%windir%\system32\sysprep”,然后通过 Powershell 从我本地计算机的管理员模式执行“sysprep /generalize”。我该怎么做?
根据您的要求,据我所知,您可以使用 PowerShell 脚本来实现它。首先,您可以看一下 Sysprep,它可以是 PowerShell 命令 C:\WINDOWS\system32\sysprep\sysprep.exe /generalize /shutdown /oobe
中的 运行。将此命令放在脚本中,然后您可以使用两种方法从本地计算机在 VM 中 运行 此脚本。一种是使用调用命令。
在 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
。
运行ning 后的输出:-
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
我有一个 windows Azure 虚拟机,需要执行“%windir%\system32\sysprep”,然后通过 Powershell 从我本地计算机的管理员模式执行“sysprep /generalize”。我该怎么做?
根据您的要求,据我所知,您可以使用 PowerShell 脚本来实现它。首先,您可以看一下 Sysprep,它可以是 PowerShell 命令 C:\WINDOWS\system32\sysprep\sysprep.exe /generalize /shutdown /oobe
中的 运行。将此命令放在脚本中,然后您可以使用两种方法从本地计算机在 VM 中 运行 此脚本。一种是使用调用命令。
在 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
。
运行ning 后的输出:-
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