Write custom logs via PowerShell
using namespace System.Net
# Input bindings are passed in via param block.
param( TriggerMetadata)
# Interact with query parameters or the body of the request.
Function Build-Signature ( sharedKey, contentLength, contentType, $resource){
$sha256 = New-Object System.Security.Cryptography.HMACSHA256
return $authorization
}
Function Post-LogAnalyticsData ( sharedKey, logType){
$method = "POST"
$contentType = "application/json"
$resource = "/api/logs"
$rfc1123date = ([DateTime]::UtcNow).ToString("r")
$headers = @{
"Authorization" = $signature;
"Log-Type" = $logType;
"x-ms-date" = $rfc1123date;
}
return $response.StatusCode
}
$customerId = "06637cbc-c2ea-4093-acc8-fff2aac4fc6c"
$sharedKey = "ap7wS+3ec1DLA/2X/0BDiG7ojrAi9U3EI16o3VhrGeH74KWwrtUmVB5eS9V0vQPWTBLXmU9ZGQy8n1AInChkpw=="
$LogType = "ADDCNetlogonLogs"
$Properties = [Ordered] @{
"ComputerName" = $env:computername
"User" = $env:Username
}
#Submit the data to the API endpoint
$params = @{
CustomerId = $customerId
SharedKey = $sharedKey
Body = ([System.Text.Encoding]::UTF8.GetBytes($CustomLogs))
LogType = $LogType
}
$LogResponse = Post-LogAnalyticsData @params
$LogResponse