azure - 用于修改/更新 Azure VM 标记值的代码在 Azure PowerShell Runbook 中不起作用

标签 azure powershell azure-powershell azure-runbook

我正在更新/修改 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 即可工作。

enter image description here

enter image description here

关于azure - 用于修改/更新 Azure VM 标记值的代码在 Azure PowerShell Runbook 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56678567/

相关文章:

php - 通过PowerShell从JSON数组中提取特定对象作为逗号分隔的字符串

.net - 使用WMI查询已登录用户的结果很奇怪

azure - 如何在azure中提取资源级别的所有标签

Azure DevOps Pipeline Azure Blob 存储上传文件 403 禁止异常

authentication - 多个应用程序使用单个 Azure 移动服务进行实时身份验证?

c# - Azure 究竟如何提供扩展?

azure - 用于辅助角色配置的 WaIISHost.exe.config 与 app.config

Azure KQL 正则表达式使用 extract_all() 捕获命名捕获组的句子

windows - Powershell where-object 返回代码

powershell - 在单个 Azure Powershell 命令中使用多个订阅