Automation Runbook Logging Differences

Erin Dempster 21 Reputation points
2025-11-17T22:09:34.45+00:00

After converting Azure Automation runbooks from PowerShell 5.1 to 7.4, we are seeing some issues in the output logging in Azure Automation. We're getting a lot of gibberish when we run the runbook on a Windows 11 VM used as a Hybrid worker. However, when using the built-in Azure "Sandbox" worker, it's logging as expected. Below are examples of running a short test in each worker type.

What configuration changes are needed on the Windows 11 VM, so we get the expected logging output, not the gibberish?

The function/cmdlet used is not important. I intentionally used an invalid function to generate the error output.

Expected output - as seen in Test Panel with Azure "Sandbox" Worker

Get-KeyVault: 
Line |
   4 |  Get-KeyVault
     |  ~~~~~~~~~~~~
     | The term 'Get-KeyVault' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.


Current output from Hybrid Worker VM

Get-KeyVault: C:\ProgramData\Microsoft\System Center\Orchestrator\7.2\SMA\Sandboxes\e4kxtt5m.gvu\Temp\jprfahrf.ehk\b6b2393d-9ab4-4ea0-8e1d-377553d8ed92.ps1:4
Line |
   4 |  Get-KeyVault
     |  ~~~~~~~~~~~~
     | The term 'Get-KeyVault' is not recognized as a name of a cmdlet, function, script file, or executable program.
     | Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
{count} votes

1 answer

Sort by: Most helpful
  1. Q&A Assist
    2025-11-17T22:09:52.8366667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The issue you are experiencing with the logging output on the Windows 11 VM used as a Hybrid worker may be related to the differences in how PowerShell 7.x handles output compared to PowerShell 5.1. In PowerShell 7.x, the output may include ANSI escape sequences for formatting, which can appear as gibberish if the output is not rendered correctly in the environment you're using.

    To resolve this issue and achieve the expected logging output, you can try the following configuration changes on the Windows 11 VM:

    1. Disable ANSI Escape Sequences: You can configure your PowerShell session to disable ANSI escape sequences. This can be done by setting the $OutputPreference variable at the beginning of your runbook:
         $OutputPreference = "SilentlyContinue"
      
      This setting will suppress the output that includes formatting codes.
    2. Explicitly Set Logging Preferences: Ensure that you explicitly set the logging preferences at the start of your runbook as follows:
         $VerbosePreference = "Continue"
         $ProgressPreference = "Continue"
      
      This will help ensure that the logging behaves as expected.
    3. Check PowerShell Version Compatibility: Ensure that all modules you are using are compatible with PowerShell 7.x, as some modules may behave differently or have known issues when run in this environment.
    4. Review Runbook Code: If your runbook is dependent on specific internal paths or uses features not supported in PowerShell 7.x, consider revising the code to avoid these dependencies.

    By implementing these changes, you should be able to achieve logging output similar to what you see in the Azure "Sandbox" worker.

    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.