I have written a script to monitor Azure Automation jobs.
It goes through the jobs and gets its error's stream and uses it add to an object among other properties. The issue is that, when executing from an Azure Automation account, the job's "summary" property, it gets truncated to about 85 chars. When executing from my laptop, all works as expected and I get the full property value.
Example from my computer:
,"Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and then try running the command again.",
Same string from the error log when the script is ran from Azure Automation Runbook:
,"Cannot validate argument on parameter 'Identity'. The argument is null. Provide ...",
The code I have executing is:
$JobErrorOutputStreamEvents = Get-AzAutomationJobOutput -Id $Job.JobId -ResourceGroupName $ResourceGroupName -AutomationAccountName $AutomationAccountName -Stream Error
# Logs job error events
foreach ($JobErrorOutputStreamEvent in $JobErrorOutputStreamEvents) {
# Adds the Error streams to Job Errors Log
$Properties = [ordered] @{
Runbook = $Runbook.Name
JobId = $Job.JobId
JobStatus = $Job.Status
JobStatusDetails = $Job.StatusDetails
EventTime = $JobErrorOutputStreamEvent.Time
Summary = $JobErrorOutputStreamEvent.Summary
JobStartTime = $Job.StartTime
JobEndTime = $Job.EndTime
AutomationAccountName = $AutomationAccountName
ResourceGroupName = $ResourceGroupName
Subscription = $SubcriptionName
}
$JobErrorsLog += New-Object -TypeName PSObject -Property $Properties
$Time = Get-Date -Format "yyyy-MM-dd hh:mm:ss K"
$MsgErrorFoundInJob = "[Info] Runbook `"$($Runbook.Name)`" - Error found in Job ID `"$($Job.JobId)`", happening at $($JobErrorOutputStreamEvent.Time)!"
Write-Output $MsgErrorFoundInJob
$Log += "[$Time] $($MsgErrorFoundInJob)"
}
Once more, I must stress that the code is fine and I get the full error "Summary" if executing from my computer.
Tried using Select-Object -ExpandProperty Summary, but it does not change anything.
Can someone help?