gpt4 book ai didi

azure - 配置失败。 VM 'VM Name' 的操作系统配置未在分配的时间内完成

转载 作者:行者123 更新时间:2023-12-03 00:27:12 28 4
gpt4 key购买 nike

我是 Azure 新手。我正在尝试使用 powershell 在 Azure 中创建资源。

我的要求是从虚拟机创建镜像。我遵循了以下方法:

流程 1:手动执行
通用化虚拟机:登录虚拟机 -> 打开命令提示符 -> cd %windir%\system32\sysprep -> 运行 sysprep.exe -> 检查通用化按钮 -> 关闭。

创建快照:转到Azure门户->转到通用的VM-->单击“捕获”按钮-->提供图像名称并提及资源组,然后单击“创建”。

这将创建一个图像。

流程 2:使用 powershell 进行

   # create session of the VM

$UserName = "$IPAddress\$adminUsername"
$Password = ConvertTo-SecureString $adminPassword -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($UserName, $Password)
$s = New-PSSession -ComputerName $IPAddress -Credential $psCred

# Run SysPrep for generalizing the VM

$sysprep = 'C:\Windows\System32\Sysprep\Sysprep.exe'
$arg = '/generalize /oobe /shutdown /quiet'
Invoke-Command -Session $s -ScriptBlock {param($sysprep,$arg)Start-Process -FilePath $sysprep -ArgumentList $arg} -ArgumentList $sysprep,$arg

#Stop the VM

Stop-AzureRmVM -ResourceGroupName $ResourceGroupName -Name $virtualMachineName -Force


# Generalize the VM

Set-AzureRmVM -ResourceGroupName $ResourceGroupName -Name $virtualMachineName -Generalized

# Create the Image

$vm = Get-AzureRmVM -Name $virtualMachineName -ResourceGroupName $ResourceGroupName
$image = New-AzureRmImageConfig -Location $location -SourceVirtualMachineId $vm.ID
New-AzureRmImage -Image $image -ImageName $ImageName -ResourceGroupName $ResourceGroupName

两个进程都会创建一个图像。但我在这里面临的问题是,当我从 Process 1 创建的镜像旋转 VM 时,它已成功创建,没有任何问题。
但是,当我从 Process2 创建的镜像旋转 VM 时,它正在创建,但出现以下错误消息:

Provisioning failed. OS Provisioning for VM 'VM Name' did not finish in the allotted time. However, the VM guest agent was detected running. This suggests the guest OS has not been properly prepared to be used as a VM image (with CreateOption=FromImage).

谁能告诉我我在 powershell 脚本上做错了什么,我收到了这个错误。

最佳答案

时间似乎是问题所在。

Sysprep 通常需要 10 - 15 分钟,您没有 sleep 时间。一旦发送 sysprep 脚本,您就会关闭虚拟机,没有时间实际 sysprep 系统。

您可以设置 sleep 时间或循环来检查虚拟机何时处于已停止状态。

关于azure - 配置失败。 VM 'VM Name' 的操作系统配置未在分配的时间内完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54784018/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com