从PowerShell中的旧映像创建Azure计算机时的安全类型问题

pobjuy32  于 5个月前  发布在  Shell
关注(0)|答案(1)|浏览(74)

我尝试从主映像自动创建机器,为此我创建了操作系统磁盘的映像。当我尝试创建新机器时,我总是得到相同的错误。
图像创建:

$randomInt = Get-Random -Minimum 1000 -Maximum 9999
$masterVM = Get-AzVM -ResourceGroupName $rgName -Name $masterNameVM
$masterImageName = "MASTER-IMAGE-" + (Get-Date -Format 'dd-MM-yy') + "-" + $randomInt
$masterImageConfig = New-AzImageConfig -Location $location -HyperVgeneration "V2" 
$masterImageConfig = Set-AzImageOsDisk -Image $masterImageConfig -OsState "Generalized" -OsType "Windows" -ManagedDiskId $masterVM.StorageProfile.OsDisk.ManagedDisk.Id
$masterImage = New-AzImage -ImageName $masterImageName -ResourceGroupName $rgName -Image $masterImageConfig

字符串
虚拟机创建:

for ($i = 1; $i -le $machineCount; $i++) {
    $tmpName = $sessionHostNamePrefix + "-" + $i

    $pip = New-AzPublicIpAddress -ResourceGroupName $rgName -Location $location -Name "$tmpName-pip" -AllocationMethod Static -IdleTimeoutInMinutes 4 -Force
    $nic = New-AzNetworkInterface -ResourceGroupName $rgName -Location $location -Name "$tmpName-nic" -SubnetId (Get-AzVirtualNetwork -ResourceGroupName $rgName -Name $vnetName).Subnets[0].Id -PublicIpAddressId $pip.Id -NetworkSecurityGroupId (Get-AzResource -ResourceGroupName $rgName -Name $nsgName).ResourceId -Force

    $tmpConfig = New-AzVMConfig -VMName "$tmpName-Vm" -VMSize $masterVM.HardwareProfile.Vmsize
    $tmpConfig = Set-AzVMOperatingSystem -VM $tmpConfig -Windows -ComputerName $tmpName -Credential $creds -ProvisionVMAgent -EnableAutoUpdate
    $tmpConfig = Add-AzVMNetworkInterface -VM $tmpConfig -Id $nic.Id
    $tmpConfig = Set-AzVMSourceImage -VM $tmpConfig -Id $masterImage.Id
    $tmpConfig = Set-AzVmUefi -VM $tmpConfig -EnableVtpm $true -EnableSecureBoot $true;
    $tmpConfig = Set-AzVMOSDisk -VM $tmpConfig -Name "$tmpName-OsDisk" -Caching "ReadWrite" -CreateOption "FromImage" -Windows
    $tmpConfig = Set-AzVMSecurityProfile -VM $tmpConfig -SecurityType "TrustedLaunch"

    New-AzVM -ResourceGroupName $rgName -Location $location -VM $tmpConfig -Verbose -Zone $masterVM.Zones 
}


输出量:

New-AzVM: 
Line |
  15 |      New-AzVM -ResourceGroupName $rgName -Location $location -VM $tmpC …
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Resource 'LP-AVD-1-OsDisk' should have same Security type as the source resource 'MASTER-IMAGE-01-12-23-2727_0_crctds5jdgw'.
ErrorCode: OperationNotAllowed
ErrorMessage: Resource 'LP-AVD-1-OsDisk' should have same Security type as the source resource 'MASTER-IMAGE-01-12-23-2727_0_crctds5jdgw'.
ErrorTarget: /subscriptions/XXXXXXXXXXXXXXX/resourceGroups/XXXXXXXXXXXXXXXX/providers/Microsoft.Compute/disks/LP-AVD-1-OsDisk
StatusCode: 409
ReasonPhrase: 
OperationID : 722167e4-83ae-4caf-8f33-bda5dfe522ec


$masterVM.SecurityProfile.SecurityType的值:TrustedLaunch
我完全迷路了。谁能告诉我我错过了什么?
提前感谢你的帮助

iq0todco

iq0todco1#

我终于找到了问题的原因。实际上,从“Trusted Launched”SecurityType映像创建VM是不可能的。我通过更改函数的顺序并对其进行轻微修改来实现这一点。
另一个问题是,不可能将虚拟机、磁盘或快照从SecurityType“Trusted Launched”转换为Standard。

相关问题