How to pass parameters containing backslash in Start-AzAutomationRunbook correctly with Hybrid Workers and Powershell 7

Martin Preishuber 0 Reputation points
2026-05-21T06:08:38.4766667+00:00

Hi,

I'm trying to call one Powershell 7 Azure runbook from another one by using

Start-AzAutomationRunbook

There is one parameter containing backslash characters (basically an UNC path), so it looks like this

$Params  = @{ 
    "param" = "\\myserver\myshare"
}

Start-AzAutomationRunbook -AutomationAccountName "account" -Name 'childrunbook' -ResourceGroupName 'rg' -DefaultProfile $AzureContext -Parameters $Params -Wait

The child runbook has a string param

param
(
    [Parameter(Mandatory = $false)]
    [string]$param
)

When running the child runbook the input parameter is always shown as "\\myserver\myshare", so apparently the backslash gets quoted with another backslash.

The interesting thing is, that the parameter within the child runbook has a different value depending on whether the child runbook is running in Azure or on a Hybrid worker (with '-runon "hybridworkergroup"'):

  • in Azure: apparently the param value get's properly decoded, the value of $param is "\myserver\myshare"
  • on a Hybrid Worker: the param stays as it is, so the value of $param is still "\\myserver\myshare"

Is this some kind of expected behaviour or is it a bug?

Thanks & BR,

Martin

Azure Automation
Azure Automation

An Azure service that is used to automate, configure, and install updates across hybrid environments.


1 answer

Sort by: Most helpful
  1. AI answer

    2026-05-21T06:08:52.05+00:00

    This behavior is expected given how parameters are serialized and deserialized when starting runbooks, especially across Hybrid Runbook Workers.

    Start-AzAutomationRunbook sends parameter values through the Azure Automation web service. Parameters are serialized (often via JSON or similar mechanisms) and then deserialized on the worker. For string values that contain backslashes (like UNC paths), this serialization layer escapes backslashes as \\ during transport.

    In Azure sandboxes, the runtime is correctly unescaping the value so the runbook parameter ends up as \\server\share (PowerShell literal for \\server\share), which is what is expected for a UNC path.

    On Hybrid Runbook Workers, the same parameter is not being unescaped in the same way, so the runbook receives the raw escaped representation (\\\\server\\share), which is why the input view shows doubled backslashes. This difference is due to how Hybrid Runbook Workers handle the parameter payload, not to how the parameter is defined in the runbook.

    To work around this on Hybrid Runbook Workers, normalize the parameter value at the start of the child runbook, for example by replacing double backslashes with single backslashes:

    param(
        [Parameter(Mandatory = $false)]
        [string]$param
    )
    
    # Normalize UNC path if it arrived double-escaped
    $param = $param -replace '\\\\', '\\'
    

    This keeps the calling pattern with Start-AzAutomationRunbook unchanged and ensures the child runbook always works with a correctly formatted UNC path, regardless of whether it runs in Azure or on a Hybrid Runbook Worker.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.