You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure中PowerShell加入VM至Update Manager仅手动生效问题求助

解决方案

1. 确认Update Management解决方案已启用

确保关联的Log Analytics工作区中已启用Update Management解决方案,手动配置时该步骤会自动完成,但自动化脚本需单独处理:

# 获取目标工作区
$workspace = Get-AzOperationalInsightsWorkspace -ResourceGroupName <资源组名> -Name <工作区名>

# 检查并启用Updates解决方案
$solution = Get-AzOperationalInsightsIntelligencePack -ResourceGroupName $workspace.ResourceGroupName -WorkspaceName $workspace.Name | Where-Object Name -eq "Updates"
if (-not $solution.Enabled) {
    Set-AzOperationalInsightsIntelligencePack -ResourceGroupName $workspace.ResourceGroupName -WorkspaceName $workspace.Name -IntelligencePackName "Updates" -Enabled $true
}

2. 修正VM扩展配置

你的Set-AzVMExtension命令存在参数不规范问题,调整为符合官方标准的配置:

  • ExtensionName 需使用MicrosoftMonitoringAgent(MMA扩展的官方默认名称)
  • 确保Settings中所有参数值来源正确(从Automation/VM资源对象直接获取,避免手动输入错误)

修正后的命令示例:

# 获取Automation账户核心参数
$automationAccount = Get-AzAutomationAccount -ResourceGroupName <自动化账户资源组> -Name <自动化账户名>
$registrationUrl = $automationAccount.RegistrationUrl
$aaId = $automationAccount.Id

# 获取VM资源ID
$vm = Get-AzVM -ResourceGroupName $resourceGroupName -Name $vmName
$resourceId = $vm.Id

# 安装并配置MMA扩展
Set-AzVMExtension -ExtensionName "MicrosoftMonitoringAgent" `
                  -Location $location `
                  -ResourceGroupName $resourceGroupName `
                  -VMName $vmName `
                  -Publisher "Microsoft.EnterpriseCloud.Monitoring" `
                  -ExtensionType "MicrosoftMonitoringAgent" `
                  -TypeHandlerVersion "1.0" `
                  -Settings @{
                      "workspaceId" = $workspaceId;
                      "azureResourceId" = $resourceId;
                      "AutomationAccountURL" = $registrationUrl;
                      "AzureAutomationAccountId" = $aaId;
                      "stopOnMultipleConnections" = $True
                  } `
                  -ProtectedSettings @{
                      "workspaceKey" = $workspaceKey
                  }

3. 手动注册VM到Update Management

仅安装MMA扩展不足以让VM出现在Update Management列表中,需执行注册步骤:

Set-AzAutomationUpdateManagementAzureVM -ResourceGroupName $automationAccount.ResourceGroupName `
                                        -AutomationAccountName $automationAccount.Name `
                                        -VMResourceId $resourceId

4. 验证与同步

  • 检查扩展安装状态,确保ProvisioningState为Succeeded:
Get-AzVMExtension -ResourceGroupName $resourceGroupName -VMName $vmName -Name "MicrosoftMonitoringAgent"
  • 等待15-30分钟,让Log Analytics工作区与Automation账户完成同步,之后刷新Update Management页面查看VM是否显示。

5. 日志排查(若问题仍存在)

查看VM本地MMA扩展日志(路径:C:\Program Files\Microsoft Monitoring Agent\Agent\Logs\HealthService.log),或在Log Analytics工作区中查询注册事件:

UpdateManagementEvents
| where TimeGenerated > ago(24h)
| where Computer == "<VM名称>"
| project TimeGenerated, OperationName, Status, Description

内容的提问来源于stack exchange,提问作者Santi Gamboa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 03:23:34