我正在更新/修改 Azure VM 标记值,当我在我的本地 PowerShell ISE 上测试它并连接到我们的 Azure 订阅时,代码成功运行(它成功修改了现有的标记值)但是当我在我们的 Azure PowerShell 中测试它时Azure 门户中的 Runbook。该代码无法正常工作,而是删除了所有现有标签。
这是我从 link 中搜索的示例代码:
#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
最佳答案
我可以重现您的问题,正如@4c74356b41 的评论,您应该更新您的模块。更新模块后AzureRM.Compute
, AzureRM.Profile
, AzureRM.Resources
直接从Shared Resources-Modules--Browse Gallery--搜索AzureRM.Compute等各个模块--点击进口 .更新这些模块后,此 Runbook 即可工作。
关于azure - 用于修改/更新 Azure VM 标记值的代码在 Azure PowerShell Runbook 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56678567/