Azure Automation truncates job error stream summary

Filipe Simões 20 Reputation points
2024-01-08T17:37:17.2433333+00:00

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?

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,366 questions
Windows for business | Windows Server | User experience | PowerShell
{count} votes

Accepted answer
  1. AnuragSingh-MSFT 21,546 Reputation points Moderator
    2024-01-10T09:20:57.6433333+00:00

    Filipe Simões, thank you for reporting this issue with details.

    I tested the shared cmdlet for Get-AzAutomationJobOutput and noticed that the truncation of output is only happening for runbook of type PowerShell v5.1

    You can use the same code in a new runbook of PowerShell v7.2 type and this should not be an issue.

    I will try to get some more details about this for PowerShell v5.1 type runbook and share here.

    Hope this helps.

    If the answer helped, please click Accept answer so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.