Updated Code
for the part 2 of the script
############## END USER SPECIFIED VARIABLES ###############
# Make sure to have the $body as a JSOn Array
$EventBody = $EventGridEvent | ConvertTo-Json -AsArray
# Sending the data to Log Analytics via the DCR!
$headers = @{"Authorization" = "Bearer $bearerToken"; "Content-Type" = "application/json"}
#$headers | Out-String | Write-Host
$uri = "$DceURI/dataCollectionRules/$DcrImmutableId/streams/Custom-$Table"+"_CL?api-version=2021-11-01-preview"
#$uri | Out-String | Write-Host
try
{
Invoke-RestMethod -Uri $uri -Method "POST" -Body $EventBody -Headers $headers | Out-String | Write-Host
}
catch
{
Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
Write-Host "Message:" $_.ErrorDetails.Message
}