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

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

我有一个 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/

相关文章:

azure - 执行 Azure 函数 cmdlet Get-AzADAppCredential 的权限不足

azure - 如何为 Azure 中的不同插槽使用不同的 Web.config 文件

javascript - Azure 在隐式流程登录期间使用错误的回调 URL

angular - Azure CDN - 与 Verizon 结合 Identity Server 4 重写 Angular 应用程序的 URL

windows - Powershell 打开系统控制面板而不是执行代码

azure - 获取-AzureADPolicy : The term 'Get-AzureADPolicy' is not recognized

azure - Terraform 在未指定的情况下强制将值设置为 null

MySQL 查询异常从 Powershell v4 调用 "Fill"并使用 "2"参数

powershell - 无法在 Powershell Get-Eventlog 中获取 ComputerName

azure - 如何使用 azure powershell 命令获取特定 azure 资源组中存在的 azure 逻辑应用列表