2

我正在更新/修改 Azure VM 标记值,当我在我的本地 PowerShell ISE 上测试它并连接到我们的 Azure 订阅时,代码成功运行(它成功修改了现有的标记值)但是当我在我们的 Azure PowerShell 中测试它时Azure 门户中的 Runbook。该代码无法正常工作,而是删除了所有现有标签。

这是我从这个链接搜索的示例代码:

#Get all tags from Resource (VM)
$GetVM = Get-AzureRMVM -Name 'myVM' -ResourceGroupName 'myrg'
$tags = (Get-AzureRMVM -ResourceName $GetVM.Name -ResourceGroupName $GetVM.ResourceGroupName).Tags

#Modifying the value of the Tag
$tags['tag1'] = "value1"

#Updating the Tags
$UpdateTag = Set-AzureRmResource -Tag $tags -ResourceName $GetVM.Name -ResourceGroupName $GetVM.ResourceGroupName -ResourceType Microsoft.Compute/virtualMachines -Force
4

1 回答 1

1

我可以重现您的问题,正如@4c74356b41 的评论,您应该更新您的模块。在我更新模块AzureRM.ComputeAzureRM.ProfileAzureRM.Resources直接从 Shared Resources-Modules--Browse Gallery--搜索每个模块,如 AzureRM.Compute--单击Import。更新这些模块后,此 Runbook 即可工作。

在此处输入图像描述

在此处输入图像描述

于 2019-06-20T09:09:09.113 回答