Extend truncated powershell error output | Get-AzAutomationJobOutputRecord

Hitender Singh 131 Reputation points
2021-06-03T08:36:08.783+00:00

Hi,

I am trying to run the below cmdlet but the output is truncated and I am unable to expand it.
Get-AzAutomationJobOutput -Id $job.JobId -AutomationAccountName Myautomation -ResourceGroupName MyautomationRG -Stream "any" |
Get-AzAutomationJobOutputRecord | select summary -ExpandProperty summary

Eventually what I am trying to achieve is, to store the azure runbook job all outputs to a txt file in SPO using the below code but the output was truncated.

$job = Start-AzAutomationRunbook -ResourceGroupName "MyautomationRG" `  
  -AutomationAccountName "Myautomation" -Name "outputwithverbose"  
  
$doLoop = $true  
While ($doLoop) {  
  $job = Get-AzAutomationJob -ResourceGroupName "MyautomationRG" `  
    -AutomationAccountName "Myautomation" -Id $job.JobId  
  $status = $job.Status  
  $doLoop = (($status -ne "Completed") -and ($status -ne "Failed") -and ($status -ne "Suspended") -and ($status -ne "Stopped"))  
}  
  
Get-AzAutomationJobOutput -ResourceGroupName "MyautomationRG" `  
  -AutomationAccountName "Myautomation" -Id $job.JobId -Stream Output  
  
# For more detailed job output, pipe the output of Get-AzAutomationJobOutput to Get-AzAutomationJobOutputRecord  
$logoutput = Get-AzAutomationJobOutput -ResourceGroupName "MyautomationRG" `  
  -AutomationAccountName "Myautomation" -Id $job.JobId -Stream Any | Get-AzAutomationJobOutputRecord | Out-String  
  
  $logoutputarray = Get-AzAutomationJobOutput -ResourceGroupName "MyautomationRG" `  
  -AutomationAccountName "Myautomation" -Id $job.JobId -Stream Any | Get-AzAutomationJobOutputRecord  
  
  $stream = [IO.MemoryStream]::new([Text.Encoding]::UTF8.GetBytes($logoutput))  
Add-pnpfile -Folder "Shared Documents" -FileName "logoutputs.txt" -Stream $stream  

Screenshot from the local machine - powershell.
101908-image.png

Complete output on runbook job details
102020-image.png

I wonder how can I get the complete output in powershell. Thank you

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

2 answers

Sort by: Most helpful
  1. svijay-MSFT 5,256 Reputation points Microsoft Employee Moderator
    2021-06-10T10:44:43.717+00:00

    @Hitender Singh - Thanks for your question.

    Per my initial research, Get-AzAutomationJobOutput cmdlet lists one or more job output records, it returns only a summary, as a string, - Truncated output
    The Get-AzAutomationJobOutputRecord cmdlet gets the full output of an Automation job output record and may meet your requirement.

    The below is the snippet that I tried at my end.

    $jobs = Get-AzAutomationJobOutput -Id <JOBID> -ResourceGroupName <RG> -AutomationAccountName <ACCOUNTNAME>  
    foreach($job in $jobs)  
    {  
     $job.StreamRecordId  
    $record = Get-AzAutomationJobOutputRecord -Id $job.StreamRecordId -JobId $job.JobId -ResourceGroupName <RG> -AutomationAccountName <ACCOUNTNAME> - | Select-Object -ExpandProperty Value   
    $record.value  
    }  
    

    Truncated Output with Get-AzAutomationJobOutput

    104219-image.png

    Output in the portal:

    104220-image.png

    Output running the above snippet:

    104252-image.png

    -----------------------------

    Please do not forget to "Accept the answer" wherever the information provided helps you. This will help others in the community as well.

    1 person found this answer helpful.
    0 comments No comments

  2. Olakunori, Yemi (Temporary Employee) 0 Reputation points
    2024-10-11T01:12:33.89+00:00

    Thanks, I had the same issue and stumbled on this fix. It worked.

    0 comments No comments

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.