PowerShell 7.x Runbook limitations

I was looking forward to migrating my Runbooks from 5.1 to 7.2 but hit a roadblock today. I have a PowerShell function that checks if the runbook is already running, and quits if it is. Looks like Microsoft too provides one in in their docs (came across it today when Googling on what my current issue).

This function depends on a PSPrivateMetadata environment variable to get the running job’s Id. But that’s missing in PowerShell 7.1 & 7.2. No mention of this in the official docs. That’s a bummer.

Another bummer is that they don’t support signed runbooks. That’s a no go for me. One more bummer, which I was aware of, is that they don’t support source control integration – it creates the runbooks as 5.1.

Update (2nd Sept 2023): Noticed that PSPrivateMetadata is available in a new PowerShell 7.2. automation account I deployed.

My current approach to determine if the code I am executing is within an Azure Automation account or not is the following:

The $env:AZUREPS_HOST_ENVIRONMENT variable is currently not present in Azure Automation account PowerShell 7.2.

Update (26th Sept 2023): However, PSPrivateMetadata is missing when using PowerShell 7.2 with a Hybrid Runbook Worker! Aaaaargh!