【问题标题】:How to run "sysprep /generalize” in Azure Windows Virtual Machine (VM) from my local machine using Powershell?如何使用 Powershell 从我的本地计算机在 Azure Windows 虚拟机 (VM) 中运行“sysprep /generalize”?
【发布时间】:2020-09-09 06:58:19
【问题描述】:

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

【问题讨论】:

  • 这个问题有什么更新吗?它解决了你的问题吗?

标签: azure powershell azure-powershell powershell-remoting azure-vm


【解决方案1】:

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

另一个是使用虚拟机扩展。这有点复杂。您可以查看 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

【讨论】:

  • 嘿查尔斯,很抱歉更新晚了。我能够成功执行它,我已经在您的答案中更新了我的输出,它是假定的正确输出吗?你能确认一下吗?
  • @Chaitanya 当然可以。好吧,如果它适合你,请接受它作为答案。
猜你喜欢
  • 2020-09-16
  • 1970-01-01
  • 2021-03-08
  • 1970-01-01
  • 1970-01-01
  • 2017-01-07
  • 1970-01-01
  • 1970-01-01
  • 2018-01-09
相关资源
最近更新 更多