将日志分析工作区添加到 Azure VM 而不替换现有工作区

时间:2021-01-12 16:05:02

标签: azure powershell

我有以下 Powershell 命令

Set-AzVMExtension -ExtensionName "MicrosoftMonitoringAgent" `
                -ResourceGroupName "rg-xxxx" `
                -VMName "vm-xxxx" `
                -Publisher "Microsoft.EnterpriseCloud.Monitoring" `
                -ExtensionType "MicrosoftMonitoringAgent" `
                -TypeHandlerVersion "1.0" `
                -Settings @{"workspaceId" = "xxxx" } `
                -ProtectedSettings @{"workspaceKey" = "xxxx"} `
                -Location "uksouth"

它成功地将 VM 上的所有日志分析工作区替换为我在命令中配置的工作区。 我想要做的只是添加工作区而不替换已经配置的工作区。

ARM 具有相同的行为。看起来如果已经有一个工作区,那么它会被覆盖,如果那里有两个工作区,那么其中一个会被覆盖。

有谁知道在 Powershell 中只添加工作区而不覆盖的任何方法? 谢谢, 尼尔。

1 个答案:

答案 0 :(得分:0)

当我们使用 Log Analytics 代理虚拟机扩展在 Azure VM 上安装 Log Analytics 代理时,我们只需将虚拟机注册到一个现有的 Log Analytics 工作区。每次我们安装扩展程序时,微软都会替换旧的配置文件。详情请参阅here

如果要添加工作区,请参阅document