简体   繁体   English

如何使用 ARM 模板将多个 Azure VM 连接到日志分析工作区?

[英]How to connect multiple Azure VMs to log analytics workspace using ARM template?

I can able to connect the Azure VM to the log analytics workspace using the ARM template( https://docs.microsoft.com/en-us/azure/azure-monitor/agents/resource-manager-agent ) but I want to connect the multiple VMs at a time in one subscription and different resource groups to the log analytics workspace. I can able to connect the Azure VM to the log analytics workspace using the ARM template( https://docs.microsoft.com/en-us/azure/azure-monitor/agents/resource-manager-agent ) but I want to一次将一个订阅和不同资源组中的多个 VM 连接到日志分析工作区。 Is there any way to work around this?有没有办法解决这个问题?

If you want to add a bunch of VMs in a subscription to a log analytics workspace in Azure, we can use PowerShell command Set-AzVMExtension to implement it.如果你想在订阅中添加一堆 VM 到 Azure 中的日志分析工作区,我们可以使用 PowerShell 命令Set-AzVMExtension来实现它。

For example例如

# all windows VMs in the subscription (which you set via Set-AzContext)
$PublicSettings = @{ "workspaceId" = "" }
$ProtectedSettings = @{ "workspaceKey" = "" }
 
# Using -Status switch to get the status too
Get-AzVM -Status | Where-Object{ $_.Powerstate -eq "VM running" -and $_.StorageProfile.OsDisk.OsType -eq "Windows" } | ForEach-Object { 
    $VMName = $_.Name
    $ResourceGroupName = $_.ResourceGroupName
    $Location = $_.Location
 
    Write-Host "Processing $VMName"
 
    Set-AzVMExtension -ExtensionName "MicrosoftMonitoringAgent" `
    -ResourceGroupName "$ResourceGroupName" `
    -VMName "$VMName" `
    -Publisher "Microsoft.EnterpriseCloud.Monitoring" `
    -ExtensionType "MicrosoftMonitoringAgent" `
    -TypeHandlerVersion 1.0 `
    -Settings $PublicSettings `
    -ProtectedSettings $ProtectedSettings `
    -Location "$Location"
 
}

For more details, please refer to here and here .更多详情,请参阅此处此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过ARM模板将Azure Activity Monitor连接到Log Analytics Workspace - How to connect Azure Activity Monitor to Log Analytics Workspace via ARM template Azure 网关 ARM 模板配置诊断设置(Log Analytics 工作区) - Azure Gateway ARM template to configure diagnostic setting (Log Analytics workspace) 将具有相同名称的Azure VM连接到Log Analytics - Connect Azure VMs with the same names to Log Analytics 如何通过 powershell 将 PostgreSQL 数据库连接到 azure 中的日志分析工作区? - How to connect PostgreSQL database to log analytics workspace in azure via powershell? 如何连接 Azure 中现有的自动化帐户和 Log Analytics 工作区? - How to connect existing Automation Account and Log Analytics workspace in Azure? 如何使用 REST API 或 Nodejs ZF20E3C5E604C0AB3D6FAZFZ 将 azure 虚拟机与日志分析工作区连接起来? - How to connect azure virtual machine with log analytics workspace using REST API or Nodejs SDK? Azure Log Analytics 数据收集器的 ARM 模板 - ARM template for Azure Log Analytics Data Collector 如何使用 az CLI 获取 Azure Log Analytics 的工作区 ID? - How to get workspace ID of Azure Log Analytics using az CLI? 如何轮换 Azure 日志分析工作区的密钥 - How to rotate keys for azure log analytics workspace 使用 ARM 向 Azure 日志分析添加查询 - Adding a Query to Azure log analytics using ARM
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM