{"id":7197,"date":"2023-07-17T14:39:48","date_gmt":"2023-07-17T13:39:48","guid":{"rendered":"https:\/\/rakhesh.com\/?p=7197"},"modified":"2023-09-26T10:44:52","modified_gmt":"2023-09-26T09:44:52","slug":"powershell-7-x-runbook-limitations","status":"publish","type":"post","link":"https:\/\/rakhesh.com\/azure\/powershell-7-x-runbook-limitations\/","title":{"rendered":"PowerShell 7.x Runbook limitations"},"content":{"rendered":"

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

This function depends on a PSPrivateMetadata<\/code> 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<\/a>. That’s a bummer.<\/p>\n

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.<\/p>\n

Update (2nd Sept 2023)<\/strong>: Noticed that PSPrivateMetadata<\/code> is available in a new PowerShell 7.2. automation account I deployed.<\/p>\n

My current approach to determine if the code I am executing is within an Azure Automation account or not is the following:<\/p>\n

if (\"AzureAutomation\/\" -eq $env:AZUREPS_HOST_ENVIRONMENT -or $PSPrivateMetadata.JobId) {\r\n    # Azure\r\n} else {\r\n    # Local\r\n}<\/pre>\n

The $env:AZUREPS_HOST_ENVIRONMENT<\/code> variable is currently not present in Azure Automation account PowerShell 7.2.<\/p>\n

Update (26th Sept 2023)<\/strong>: However, PSPrivateMetadata<\/code> is missing when using PowerShell 7.2 with a Hybrid Runbook Worker! Aaaaargh!<\/p>\n","protected":false},"excerpt":{"rendered":"

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 … Continue reading PowerShell 7.x Runbook limitations<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[887],"tags":[],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/posts\/7197"}],"collection":[{"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/comments?post=7197"}],"version-history":[{"count":4,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/posts\/7197\/revisions"}],"predecessor-version":[{"id":7396,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/posts\/7197\/revisions\/7396"}],"wp:attachment":[{"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/media?parent=7197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/categories?post=7197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/tags?post=7197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}