PSPrivateMetadata is System.Collections.Hashtabl

A follow-up to a previous post… I don’t know if what I what I say below is accurate, take it with a pinch of salt.

As mentioned in that post I have a function that checks if a runbook is already running, and if so waits or quits. One of the things this function needs to do is find the job Id of the runbook, so it can use that to lookup the runbook name and other details and then find if there are other instances of it. Here’s the code I was using so far:

I have a few Hybrid Runbook Workers (HRW), and this code worked perfectly on all of them too. Last week, I decided to move one of them from one automation account to another. In the process I removed it from the Hybrid Worker Group, re-added it to another. Expecting no issues out of a mundane task like this, I was suprised when a bunch of my runbooks started to fail – the common thing being that they were all running on this newly moved HRW. The same runbook on the other HRWs were fine, but if I made it run on this one it failed.

The HRW itself was on PowerShell 7.4 – same version as others. And it was this section that was failing:

Instead of getting the job Id, I was getting this: System.Collections.Hashtable.

Not an actual hashtable, but the text System.Collections.Hashtable. So weird!

I couldn’t figure out what’s going on, and after a lot of wasted hours confirming that it was definitely this particular HRW, and all the modules on it were the same versions as the other HRWs, and so was the PowerShell version etc., I finally gave up and modified my code to work around this.

This is based on my previous hack that was no longer necessary since July 2024 with PowerShell 7.2, but now I put it back.

A few days later, though, I had a brainwave as to what might be the issue. I am not a 100% sure that is the issue, but I just wanted to blog it in case it helps anyone else. You see, the HRWs that work are on an older version of the extension – and so was the one that is now broken – but in the process of removing it from one Hybrid Worker Group and adding to another, when the extension was removed and readded the latest version got installed. And so that might be the issue. The PSPrivateMetadata variable is injected by this extension after all (according to ChatGPT, so maybe it’s hallucinating!) and if the extension has an issue injecting it (maybe the hashtable isn’t getting serialized properly) that would explain why it is a string with the type rather than a hashtable.

The best test would be to upgrade my working HRWs to the latest version and see if they too break. Didn’t want to do that as I am busy with a few critical projects, but maybe I’ll do that next month and update this post if doing that breaks those HRWs too.