Trouble invoking a script on a specific computer

This may be related to the issue raised about having hyphens in computer names. I currently have a pair of scheduled scripts that are just queueing in hangfire, and the computer names do have hyphens. However, the issue I’m writing about is that the jobs I am invoking from other automation scripts are not running on the node I want them to.

I have a script that is triggered on “Server Start” that is meant to run every script tagged “startup”:

if ([string]::IsNullOrEmpty((Get-PSUCache -Key 'PSUStartupTime'))) {
    foreach ($script in (Get-PSUScript -Integrated | where-object {$_.Tag -contains 'startup'})) {
        #Invoke-PSUScript -Name $script.name -integrated
        #Invoke-WebRequest -Uri "https://<VIP hostname>/api/v1/script/$($script.Id)" -Headers @{Authorization = "Bearer $bearer"} -Method POST -ContentType 'application/json-patch+json'  -Body @{"computer" = "$($env:COMPUTERNAME)"}
        Invoke-WebRequest -Uri "https://<VIP hostname>/api/v1/script/$($script.Id)?computer=$($env:COMPUTERNAME)" -Headers @{Authorization = "Bearer $bearer"} -Method POST -ContentType 'application/json-patch+json'
        Start-Sleep 10
    }

    Set-PSUCache -Key 'PSUStartupTime' -Value "$(Get-Date)"
}

The first commented out invoke is how it was running for a while. All of the invoked jobs here would run on the server node that invoked them. It was either updating from 3.6.4 → 3.7.9 or 3.5.5 → 3.6.4 where that functionality stopped working, but I don’t have the job histories to determine which. I hadn’t noticed they weren’t running on the correct server until today (I had seen the behavior but thought it was just a one-time issue). Regardless, the second commented invoke and the uncommented one are both attempts at forcing the jobs to execute on the node running the startup script. Neither of these produce the intended behavior; the invoked jobs run on random nodes. I also tried -ComputerName for Invoke-PSUScript just in case the documentation was wrong, but that, of course, did not work either.

Is this the correct way to force a job to run on a specific node, or am I doing it wrong? Is it a bug? I updated from 3.7.9 → 3.7.12 and they both behave the same.

Product: PowerShell Universal
Version: 3.7.12

Just thought I’d update that 3.7.13 did fix the queueing jobs. I cleared out the queues in the diagnostics panel, not sure if I needed to do that or not. But the jobs correctly run now.

Still not able to force the jobs to execute on a specific node when called using invoke-psuscript or invoke-restmethod. Tried these as the body to workaround the issue (it’s not optimal to have each node recache, but at least both servers get the cache):

{
  "computer": "ALL"
}

and

{
  "computer": ["MON02-S1E7","MON04-S1E7"]
}

We figured this out. It turned out to be an encoding issue. This is the full block needed:

$body = '{"jobParameters":[{"job":{"computername":"' + $env:COMPUTERNAME + '"}}],"computer":"' + $env:COMPUTERNAME + '","gotoJob":false}'

Invoke-RestMethod -Uri "https://<VIP hostname>/api/v1/script/$($script.Id)" -Headers @{Authorization = "Bearer $bearer"} -Method POST -ContentType 'application/json' -Body ([System.Text.Encoding]::UTF8.GetBytes($body))