Tuesday, March 19, 2024

Azure Automation Hybrid Runbook PSPrivateMetadata missing or broken

Problem: You have a Windows-based Hybrid Runbook Worker configured with PowerShell 7.2+ connected to Azure Automation and a runbook fails to find the Job ID or cannot find the PSPrivateMetadata variable.

Causes:

  • In PowerShell 7.2, it treats the PSPrivateMetadata as an environment variable, so it is in the ENV path.
  • Your version of the hybrid runbook worker extension stopped treating the ENV:PSPrivateMetadata as an object and displays it only as "System.Collections.Hashtable" instead of an *actual* hashtable (still an issue as of 2026-06-29).

Resolution:

  • If your 7.2 runbook needs the PSPrivateMetadata, just replace it with $ENV:PSPrivateMetadata. Note that with PS 5.1, you would often get the GUID as $PSPrivateMetadata.JobId.Guid...when you switch to 7.2, it supplies the guid as a string so you only need $ENV:PSPrivateMetadata to get the job id.
  • If the issue is your extension, you have to accommodate it differently - you have to use the contents of the trace.log file in your runbook worker that is auto-generated for your runbook's run and THAT should contain the jobId...I used a variant of the solution from Rakesh (you can google this issue and you'll see his solution) but am working on one that will be smart and let me do the thinking in a powershell module or script function.

No comments:

Post a Comment