[英]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.