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. Is there any way to work around this?
1 Answers
0
votes
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.
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"
}
copy
function to deploy. For more details, please refer to docs.microsoft.com/en-us/azure/azure-resource-manager/templates/… – Jim Xuvms
family of operating systems? You may have tagged it incorrectly. – HABO