Public/Send-ConnectorLog.ps1
|
function Send-ConnectorLog { [CmdletBinding()] Param( [Parameter(Mandatory = $true, Position = 0)] [string] $Text, [Parameter(Mandatory = $false, Position = 1)] [ValidateSet("Info", "Warning", "Error")] [string] $Type = "Info" ) Process { try { Invoke-RestMethod ` -Uri "$($Script:APIRoot)log" ` -Method Post ` -ContentType "application/json" ` -Body (@{ Message = $Text Type = $Type Timestamp = (Get-Date).ToUniversalTime().ToString("o") } | ConvertTo-Json -Depth 30) ` -Headers (Get-EntraIDAccessTokenHeader -Profile $Script:AccessTokenProfile) | out-null Write-Verbose "Sent log entry of type '$Type' with message: $Text" } catch { Write-Warning "Unable to send log entry of type '$Type' with message: $Text" } } } |