0

我在开发测试实验室 (DTL) 中有一些从 Azure Compute Gallery 映像创建的虚拟机。在他们的设置过程中,他们被赋予了一个到期日,我被利益相关者要求延长这个期限。

我们最近将我们的 VM 从单个 DTL 中的自定义映像创建为使用集中式 Azure 计算库的方式进行了更改。我进行了一些搜索,并使用使用自定义图像创建的旧虚拟机,以下代码运行良好,但是使用新重命名的计算库作为虚拟机的基础,代码失败并出现以下错误:

'Set-AzResource:MissingRequiredProperties:必须指定以下属性之一:customImageId、galleryImageReference。

这看起来是一个错误,因为新的 AzResource 方法不适合新的 Azure Compute Galleries。我可以从我的资源属性中看到它包含一个名为“sharedImageId”的参数,该参数已被填充,因此我假设它打算使用它。我对 Azure 的所有东西都很陌生,所以如果有人有更好的建议或想法,那就太好了。

下面的代码:

$subscriptionId = ‘<mySubscriptionID>’

$labResourceGroup = ‘<labResourceGroup>’

$labName = ‘<DTL-Name>’

$VmName = ‘virtualMachineName’

$expirationDate = ‘2022-05-31’

# Log into your Azure account  

Select-AzSubscription -SubscriptionId $subscriptionId

$VmResourceId = “subscriptions/$subscriptionId/resourcegroups/$labResourceGroup/providers/microsoft.devtestlab/labs/$labName/virtualmachines/$VmName”

$vm = Get-AzResource -ResourceId $VmResourceId -ExpandProperties

# Get all the Vm properties

$VmProperties = $vm.Properties

# Set the expirationDate property

$VmProperties | Add-Member -MemberType NoteProperty -Name expirationDate -Value $expirationDate -Force

Set-AzResource -ResourceId $VmResourceId -Properties $VmProperties -Force

`

4

0 回答 0