Skip to content

Commit 8a7a9e7

Browse files
authored
Merge pull request #103676 from sandytsang/patch-1
Update azure-monitor-agent-windows-client.md
2 parents 4ddbde3 + 8311488 commit 8a7a9e7

File tree

1 file changed

+55
-14
lines changed

1 file changed

+55
-14
lines changed

articles/azure-monitor/agents/azure-monitor-agent-windows-client.md

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@ Now we associate the Data Collection Rules (DCR) to the Monitored Object by crea
180180

181181
**Request URI**
182182
```HTTP
183-
PUT https://management.azure.com/{MOResourceId}/providers/microsoft.insights/datacollectionruleassociations/assoc?api-version=2021-04-01
183+
PUT https://management.azure.com/{MOResourceId}/providers/microsoft.insights/datacollectionruleassociations/{associationName}?api-version=2021-09-01-preview
184184
```
185185
**Sample Request URI**
186186
```HTTP
187-
PUT https://management.azure.com/providers/Microsoft.Insights/monitoredObjects/{AADTenantId}/providers/microsoft.insights/datacollectionruleassociations/assoc?api-version=2021-04-01
187+
PUT https://management.azure.com/providers/Microsoft.Insights/monitoredObjects/{AADTenantId}/providers/microsoft.insights/datacollectionruleassociations/{associationName}?api-version=2021-09-01-preview
188188
```
189189

190190
**URI Parameters**
@@ -213,12 +213,11 @@ PUT https://management.azure.com/providers/Microsoft.Insights/monitoredObjects/{
213213
| `dataCollectionRuleID` | The resource ID of an existing Data Collection Rule that you created in the **same region** as the Monitored Object. |
214214

215215

216-
### Using PowerShell
216+
### Using PowerShell for onboarding
217217
```PowerShell
218218
$TenantID = "xxxxxxxxx-xxxx-xxx" #Your Tenant ID
219219
$SubscriptionID = "xxxxxx-xxxx-xxxxx" #Your Subscription ID
220220
$ResourceGroup = "rg-yourResourseGroup" #Your resroucegroup
221-
$DCRName = "CollectWindowsOSlogs" #Your Data collection rule name
222221
223222
Connect-AzAccount -Tenant $TenantID
224223
@@ -252,35 +251,55 @@ $body = @"
252251
}
253252
"@
254253
255-
$request = "https://management.azure.com/providers/microsoft.insights/providers/microsoft.authorization/roleassignments/$newguid`?api-version=2021-04-01-preview"
254+
$requestURL = "https://management.azure.com/providers/microsoft.insights/providers/microsoft.authorization/roleassignments/$newguid`?api-version=2021-04-01-preview"
256255
257256
258-
Invoke-RestMethod -Uri $request -Headers $AuthenticationHeader -Method PUT -Body $body
257+
Invoke-RestMethod -Uri $requestURL -Headers $AuthenticationHeader -Method PUT -Body $body
259258
260259
261260
##########################
262261
263262
#2. Create Monitored Object
264263
265264
# "location" property value under the "body" section should be the Azure region where the MO object would be stored. It should be the "same region" where you created the Data Collection Rule. This is the location of the region from where agent communications would happen.
266-
267-
$request = "https://management.azure.com/providers/Microsoft.Insights/monitoredObjects/$TenantID`?api-version=2021-09-01-preview"
268-
$body = @'
265+
$Location = "eastus" #Use your own loacation
266+
$requestURL = "https://management.azure.com/providers/Microsoft.Insights/monitoredObjects/$TenantID`?api-version=2021-09-01-preview"
267+
$body = @"
269268
{
270269
"properties":{
271-
"location":"eastus"
270+
"location":`"$Location`"
272271
}
273272
}
274-
'@
273+
"@
275274
276-
$Respond = Invoke-RestMethod -Uri $request -Headers $AuthenticationHeader -Method PUT -Body $body -Verbose
275+
$Respond = Invoke-RestMethod -Uri $requestURL -Headers $AuthenticationHeader -Method PUT -Body $body -Verbose
277276
$RespondID = $Respond.id
278277
279278
##########################
280279
281280
#3. Associate DCR to Monitored Object
281+
#See reference documentation https://learn.microsoft.com/en-us/rest/api/monitor/data-collection-rule-associations/create?tabs=HTTP
282+
$associationName = "assoc01" #You can define your custom associationname, must change the association name to a unique name, if you want to associate multiple DCR to monitored object
283+
$DCRName = "dcr-WindowsClientOS" #Your Data collection rule name
284+
285+
$requestURL = "https://management.azure.com$RespondId/providers/microsoft.insights/datacollectionruleassociations/$associationName`?api-version=2021-09-01-preview"
286+
$body = @"
287+
{
288+
"properties": {
289+
"dataCollectionRuleId": "/subscriptions/$SubscriptionID/resourceGroups/$ResourceGroup/providers/Microsoft.Insights/dataCollectionRules/$DCRName"
290+
}
291+
}
292+
293+
"@
294+
295+
Invoke-RestMethod -Uri $requestURL -Headers $AuthenticationHeader -Method PUT -Body $body
296+
297+
#(Optional example). Associate another DCR to Monitored Object
298+
#See reference documentation https://learn.microsoft.com/en-us/rest/api/monitor/data-collection-rule-associations/create?tabs=HTTP
299+
$associationName = "assoc02" #You must change the association name to a unique name, if you want to associate multiple DCR to monitored object
300+
$DCRName = "dcr-PAW-WindowsClientOS" #Your Data collection rule name
282301
283-
$request = "https://management.azure.com$RespondId/providers/microsoft.insights/datacollectionruleassociations/assoc?api-version=2021-04-01"
302+
$requestURL = "https://management.azure.com$RespondId/providers/microsoft.insights/datacollectionruleassociations/$associationName`?api-version=2021-09-01-preview"
284303
$body = @"
285304
{
286305
"properties": {
@@ -290,10 +309,32 @@ $body = @"
290309
291310
"@
292311
293-
Invoke-RestMethod -Uri $request -Headers $AuthenticationHeader -Method PUT -Body $body
312+
Invoke-RestMethod -Uri $requestURL -Headers $AuthenticationHeader -Method PUT -Body $body
313+
314+
#4. (Optional) Get all the associatation.
315+
$requestURL = "https://management.azure.com$RespondId/providers/microsoft.insights/datacollectionruleassociations?api-version=2021-09-01-preview"
316+
(Invoke-RestMethod -Uri $requestURL -Headers $AuthenticationHeader -Method get).value
317+
318+
294319
```
295320

321+
### Using PowerShell for offboarding
322+
```PowerShell
323+
#This will remove the monitor object
324+
$TenantID = "xxxxxxxxx-xxxx-xxx" #Your Tenant ID
325+
$SubscriptionID = "xxxxxx-xxxx-xxxxx" #Your Subscription ID
326+
$ResourceGroup = "rg-yourResourseGroup" #Your resroucegroup
327+
328+
Connect-AzAccount -Tenant $TenantID
296329
330+
#Select the subscription
331+
Select-AzSubscription -SubscriptionId $SubscriptionID
332+
333+
#Delete monitored object
334+
$requestURL = "https://management.azure.com/providers/Microsoft.Insights/monitoredObjects/$TenantID`?api-version=2021-09-01-preview"
335+
#Invoke-RestMethod -Uri $requestURL -Headers $AuthenticationHeader -Method Delete
336+
337+
```
297338

298339
## Verify successful setup
299340
Check the ‘Heartbeat’ table (and other tables you configured in the rules) in the Log Analytics workspace that you specified as a destination in the data collection rule(s).

0 commit comments

Comments
 (0)