question

hitendersingh-1558 avatar image
0 Votes"
hitendersingh-1558 asked SathyamoorthyVijayakumar-MSFT answered

Extend truncated powershell error output | Get-AzAutomationJobOutputRecord

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

windows-server-powershellazure-automation
image.png (81.8 KiB)
image.png (123.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SathyamoorthyVijayakumar-MSFT avatar image
0 Votes"
SathyamoorthyVijayakumar-MSFT answered

@hitendersingh-1558 - 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.






image.png (4.0 KiB)
image.png (45.4 KiB)
image.png (15.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.