Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,256 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have multiple data collection rule and trying to associate DCR's in Azure Arc machines, but when I am trying using PowerShell foreach loop only last list DCR value is getting associated with azure arc machine. Other previous arc machines are getting associated but it's get deleted automatically when last DCR list is associated. I even tried this with bicep script it's not working.
I'm using below code :
$getRG = Get-AzResource | Where-Object -FilterScript {$_.ResourceType -eq 'Microsoft.HybridCompute/machines'} | Select-Object ResourceGroupName -Unique
$getRG
Write-Host "RG count: $($getRG.Count)"
$dcrNameList = @($configData.dcrExtentionName,$configData.dcrIISLogsName,$configData.dcrWindowsEventName)
Write-Host "DCR names"
$dcrNameList
foreach($dcr in $dcrNameList){
Write-Host "dataCollectionRuleAssociations from DCR: $dcr"
foreach($rg in $getRG){
Write-Host "ResourceGroup $($rg.ResourceGroupName)"
$arcVirtualMachines = Get-AzResource -ResourceGroupName $rg.ResourceGroupName -ResourceType Microsoft.HybridCompute/machines | Select-Object Name
write-host "VM count : $($arcVirtualMachines.Count)"
foreach($vm in $arcVirtualMachines){
$associationName = "$($vm.Name)-DCR-association"
$resourceUri = "/subscriptions/$($configData.subscriptionId)/resourceGroups/$($rg.ResourceGroupName)/providers/Microsoft.HybridCompute/machines/$($vm.Name)"
$dataCollectionRuleId = "/subscriptions/$($configData.subscriptionId)/resourcegroups/$($configData.resourceGroupName)/providers/Microsoft.Insights/dataCollectionRules/$dcr"
Write-Host "Associating Arc machine $($vm.Name) to $dcr in ResourceGroup $($rg.ResourceGroupName)"
New-AzDataCollectionRuleAssociation -AssociationName $associationName -ResourceUri $resourceUri -DataCollectionRuleId $dataCollectionRuleId -verbose
}
}
}