AzAutomation PS 7.2, error details empty

Tijmen Schoemaker 0 Reputation points
2026-05-28T07:02:12.0466667+00:00

When running a PS 7.2 script in AzAutomation and it errors, the details are empty. This causes you to have to open the error entry, then the pane on the right opens up with more information, the error is displayed in there. How do we fix this?

Already removed all the ansi garbage with. Tried asking CoPilot but it comes back with solutions that don't work.

if ($PSVersionTable.PSVersion.Major -ge 7 -and $null -ne $PSStyle)
{
	$PSStyle.OutputRendering = 'PlainText'
}

$env:NO_COLOR = '1'
$env:TERM = 'dumb'

Azure Automation
Azure Automation

An Azure service that is used to automate, configure, and install updates across hybrid environments.


2 answers

Sort by: Most helpful
  1. Bharath Y P 10,165 Reputation points Microsoft External Staff Moderator
    2026-05-28T16:32:42.51+00:00

    Hello Tijmen, this is actually expected behaviour with the built-in PS 7.2 sandbox in Azure Automation. by default the sandbox strips out all the ANSI/colour info and only shows you a minimal “Error happened” summary in the main job view; the full error payload lives in the right-hand pane.

    The root cause is that PowerShell 7 defaults $ErrorView toConciseView, which changes how ErrorRecord objects are serialized. The Azure Automation portal's error stream UI was built to parse the older NormalView format (used by PS 5.1), so it can't extract the "details" field from the new format — leaving the column blank.

    Your $PSStyle.OutputRendering = 'PlainText' only strips ANSI escape sequences it doesn't change the ErrorRecord structure at all.

    Add this at the very top of your runbook (alongside your existing ANSI cleanup):

    # --- Fix empty error details in Azure Automation portal ---
    $ErrorView = 'NormalView'
    $ErrorActionPreference = 'Continue'
    # Your existing ANSI cleanup (keep this too)
    if ($PSVersionTable.PSVersion.Major -ge 7 -and $null -ne $PSStyle) {
     $PSStyle.OutputRendering = 'PlainText'
    }
    

    Setting $ErrorView = 'NormalView' forces PS7 to format errors the way PS 5.1 did, which the Automation portal can parse and display in the details column.

    You can try Convert ErrorRecords to Strings: In some cases, even NormalView doesn't fully populate the details column because Azure Automation's serialization of the ErrorRecord object itself is the issue. The nuclear option is to catch errors and re-emit them as plain strings:

    $ErrorView = 'NormalView'
     
    try {
        # Your code here
        Get-Something -ErrorAction Stop
    }
    catch {
        # Convert the full ErrorRecord to a string so the portal can display it
        $errorMessage = $_.Exception.Message
        $errorPosition = $_.InvocationInfo.PositionMessage
        $fullError = "$errorMessage`n$errorPosition"
       
        Write-Error -Message $fullError
        # Or if you want it in the Output stream (always visible):
        # Write-Output "ERROR: $fullError"
    }
    

    This ensures the portal gets a plain string in the error stream rather than a complex ErrorRecord object it can't properly deserialize.

    Consider Upgrading to PowerShell 7.4 Runtime: Microsoft has deprecated PS 7.1 and 7.2 runtimes for Azure Automation. The recommendation is to move to the PowerShell 7.4 runtime (available via the Runtime Environments experience), which may have improved error stream handling.

    To upgrade:

    1. Automation Account > Runtime Environments > Create a new PS 7.4 runtime
    2. Update your runbook to use the new runtime
    3. Test in the Test pane before publishing

    https://learn.microsoft.com/en-us/azure/automation/automation-runbook-types?tabs=lps74%2Cpy10

    Hope this helps. If the information was useful, please consider accepting the answer and upvoting. Feel free to reach out if you need any further assistance. Thank you.

    Was this answer helpful?

    0 comments No comments

  2. Amira Bedhiafi 43,036 Reputation points MVP Volunteer Moderator
    2026-05-28T07:26:00.1866667+00:00

    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>"
    
    

    Was this answer helpful?


Your answer

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