An Azure service that is used to automate, configure, and install updates across hybrid environments.
Hello Tijmen !
Thank you for posting on MS Learn Q&A.
This is most likely not caused by ANSI formatting. Your $PSStyle.OutputRendering = 'PlainText', NO_COLOR and TERM=dumb settings can remove colour or escape characters but they do not control how the Azure Automation portal grid renders the job summary.
In Azure Automation, the error stream is written to job history but the portal sometimes only shows the full record after opening the stream entry and there is a difference between the short job output summary and the full output record
Get-AzAutomationJobOutput returns only a summary while Get-AzAutomationJobOutputRecord retrieves the full record.
https://learn.microsoft.com/en-us/azure/automation/automation-runbook-output-and-messages
I would treat this as a bug for PowerShell 7.x runbooks not something you can fully fix from inside the runbook.
# at the top of the runbook
$ErrorView = 'NormalView'
if ($PSVersionTable.PSVersion.Major -ge 7 -and $null -ne $PSStyle) {
$PSStyle.OutputRendering = 'PlainText'
}
$env:NO_COLOR = '1'
$env:TERM = 'dumb'
try {
# your script here
}
catch {
$msg = @"
Runbook failed
Message : $($_.Exception.Message)
Type : $($_.Exception.GetType().FullName)
Line : $($_.InvocationInfo.ScriptLineNumber)
Command : $($_.InvocationInfo.Line)
"@
# visible in job output
Write-Output "[ERROR] $msg"
# Also write to error stream
Write-Error -Message $msg
# Keep job status failed
throw $msg
}
For operational troubleshooting, I would also recommend enabling diagnostic settings for the automation account and sending JobLogs and JobStreams to Log Analytics. Azure Monitor stores job stream data with fields such as StreamType_s and ResultDescription which is usually easier to query than clicking each portal entry.
https://docs.azure.cn/en-us/automation/automation-manage-send-joblogs-log-analytics
Example KQL:
AzureDiagnostics
| where ResourceProvider == "MICROSOFT.AUTOMATION"
| where Category == "JobStreams"
| where StreamType_s == "Error"
| project TimeGenerated, RunbookName_s, JobId_g, ResultDescription
| order by TimeGenerated desc
you can retrieve the full error records like this:
Get-AzAutomationJobOutput `
-AutomationAccountName "<automation-account>" `
-ResourceGroupName "<resource-group>" `
-Id "<job-id>" `
-Stream Error |
Get-AzAutomationJobOutputRecord `
-AutomationAccountName "<automation-account>" `
-ResourceGroupName "<resource-group>"