|
| 1 | +--- |
| 2 | +title: Troubleshoot Runbook Execution Issues When Using PowerShell |
| 3 | +description: Describes some runbook execution issues that occur when you use PowerShell in Azure Automation and provides solutions to them. |
| 4 | +ms.date: 06/13/2025 |
| 5 | +ms.reviewer: adoyle, v-weizhu |
| 6 | +ms.service: azure-automation |
| 7 | +ms.custom: sap:Runbook not working as expected |
| 8 | +--- |
| 9 | +# Troubleshoot runbook execution issues when using PowerShell in Azure Automation |
| 10 | + |
| 11 | +This article provides guidance on diagnosing and resolving runbook execution issues that occur when using PowerShell scripts or cmdlets in Azure Automation. |
| 12 | + |
| 13 | +> [!NOTE] |
| 14 | +> Azure Automation enables recovery of runbooks deleted in last 29 days. You can restore a deleted runbook by running a PowerShell script as a job in your Automation account. For more information, see [Restore deleted runbook](/azure/automation/manage-runbooks#restore-deleted-runbook). |
| 15 | +
|
| 16 | +## Limitations and known issues with PowerShell runbooks |
| 17 | + |
| 18 | +PowerShell runbooks are built on Windows PowerShell. You can edit their code directly by using the text editor in the Azure portal. You can also use an offline text editor and then [import the runbooks](/azure/automation/manage-runbooks#import-a-runbook) into Azure Automation. The PowerShell version is determined by the **Runtime version** specified. |
| 19 | + |
| 20 | +**Limitations:** |
| 21 | + |
| 22 | +- For the PowerShell 7 runtime version, the module activities aren't extracted for the imported modules. |
| 23 | +- The `PSCredential` runbook parameter type isn't supported in PowerShell 7 runtime version. |
| 24 | +- PowerShell 7.x doesn't support workflows runbooks. For more information, see [PowerShell workflow](/azure/automation/automation-powershell-workflow). |
| 25 | +- PowerShell 7.x currently doesn't support signed runbooks. |
| 26 | +- Source control integration doesn't support PowerShell 7.2. PowerShell 7.2 runbooks in the source control are created in an Automation account as runtime 5.1. |
| 27 | +- Currently, only cloud jobs are supported for the PowerShell 7.2 runtime version. |
| 28 | +- Using Az modules and AzureRM modules in the same Automation account isn't supported. For more information, see [Update Azure PowerShell modules in Automation](/azure/automation/automation-update-azure-modules). |
| 29 | + |
| 30 | +**Known issues:** |
| 31 | + |
| 32 | +- Runbook properties defining logging preference isn't supported in PowerShell 7 runtime. |
| 33 | + |
| 34 | + To work around this issue, explicitly set the preference at the start of the runbook as follows: |
| 35 | + |
| 36 | + ```azurepowershell |
| 37 | + $VerbosePreference = "Continue" |
| 38 | + $ProgressPreference = "Continue" |
| 39 | + ``` |
| 40 | + |
| 41 | +- When you use the [ExchangeOnlineManagement](/powershell/exchange/exchange-online-powershell) module version 3.0.0 or later, you might experience errors. |
| 42 | + |
| 43 | + To resolve this issue, make sure that you explicitly upload the `PowerShellGet` and `PackageManagement` modules. |
| 44 | + |
| 45 | +## Before troubleshooting |
| 46 | + |
| 47 | +Follow these steps to identify and resolve common errors before further troubleshooting: |
| 48 | + |
| 49 | +1. Verify that your PowerShell script works outside of Azure Automation. |
| 50 | +2. Verify that the required modules are imported into your Azure Automation account. |
| 51 | + |
| 52 | +## Issue 1: Runbook execution fails due to deserialized object |
| 53 | + |
| 54 | +**Symptoms:** |
| 55 | + |
| 56 | +When you run a runbook, the following error message might be displayed: |
| 57 | + |
| 58 | +> Cannot bind parameter \<ParameterName>. |
| 59 | +> |
| 60 | +> Cannot convert the \<ParameterType> value of type Deserialized \<ParameterType> to type \<ParameterType>. |
| 61 | +
|
| 62 | +**Cause:** |
| 63 | + |
| 64 | +This error occurs with PowerShell Workflow runbooks because PowerShell Workflow stores complex objects in a deserialized format to persist your runbook state when the workflow is suspended. |
| 65 | + |
| 66 | +**Resolution:** |
| 67 | + |
| 68 | +To resolve this issue, use one of the following methods: |
| 69 | + |
| 70 | +- If you pipe complex objects from one PowerShell cmdlet to another one, wrap these cmdlets in an `InlineScript` activity. |
| 71 | +- Pass the name or value that you need from the complex object instead of passing the entire object. |
| 72 | +- Use a PowerShell runbook instead of a PowerShell Workflow runbook. |
| 73 | + |
| 74 | +## Issue 2: PowerShell jobs fail with the "Cannot invoke method" error |
| 75 | + |
| 76 | +**Symptoms:** |
| 77 | + |
| 78 | +When you start a PowerShell job in a runbook that runs in an Azure sandbox, you receive the following error message: |
| 79 | + |
| 80 | +> Exception was thrown - Cannot invoke method. Method invocation is supported only on core types in this language mode. |
| 81 | +
|
| 82 | +**Cause:** |
| 83 | + |
| 84 | +This error might occur because the runbook can't run in the [Full Language mode](/powershell/module/microsoft.powershell.core/about/about_language_modes). |
| 85 | + |
| 86 | +**Resolution:** |
| 87 | + |
| 88 | +To resolve this error, use one of the following methods: |
| 89 | + |
| 90 | +- Use [Start-AzAutomationRunbook](/powershell/module/az.automation/start-azautomationrunbook) instead of [Start-Job](/powershell/module/microsoft.powershell.core/start-job) to start the runbook. |
| 91 | +- Try running the runbook on a [Hybrid Runbook Worker](/azure/automation/automation-hybrid-runbook-worker). |
| 92 | + |
| 93 | +## Reference |
| 94 | + |
| 95 | +- [Troubleshoot runbook issues](/azure/automation/troubleshoot/runbooks) |
| 96 | +- [Start a runbook in Azure Automation](/azure/automation/start-runbooks) |
| 97 | +- [Run runbooks on a Hybrid Runbook Worker](/azure/automation/automation-hrw-run-runbooks) |
| 98 | +- [Update Azure PowerShell modules in Automation](/azure/automation/automation-update-azure-modules) |
| 99 | + |
| 100 | +[!INCLUDE [Azure Help Support](../../../includes/azure-help-support.md)] |
0 commit comments