What is a method for checking where an Azure Automation runbook (PowerShell) is running?
You could test using $PSPrivateMetadata
begin { if ($null -eq $PSPrivateMetadata) { throw "This command can only be run within the context of an Azure Automation Runbook Worker" } }
I had the exact same problem and did not get it to work.Ended up with another solution, I´m just running this at the top of my runbook, or directly after my param list if you have input parameters.
$checkHybridWorker = hostnameif ($checkHybridWorker -ne "myhybridworkerhostname"){ Write-Warning "Job must be started from Hybrid worker, exiting." Exit 1}
Not pretty but it works fine.