You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/automation/automation-runbook-execution.md
+15-13Lines changed: 15 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,9 +54,11 @@ The following table lists some runbook execution tasks with the recommended exec
54
54
|Run scripts that require elevation|Hybrid Runbook Worker|Sandboxes don't allow elevation. With a Hybrid Runbook Worker, you can turn off UAC and use [Invoke-Command](https://docs.microsoft.com/powershell/module/microsoft.powershell.core/invoke-command?view=powershell-7) when running the command that requires elevation.|
55
55
|Run scripts that require access to Windows Management Instrumentation (WMI)|Hybrid Runbook Worker|Jobs running in sandboxes in the cloud can't access WMI provider. |
56
56
57
-
## Runbook behavior
57
+
## Using modules in your runbooks
58
58
59
-
### Creating resources
59
+
Azure Automation supports a number of default modules, including the AzureRM modules (AzureRM.Automation) and a module containing several internal cmdlets. Also supported are installable modules, including the Az modules (Az.Automation), currently being used in preference to AzureRM modules. For details of the modules that are available for your runbooks and DSC configurations, see [Manage modules in Azure Automation](shared-resources/modules.md).
60
+
61
+
## Creating resources
60
62
61
63
If your runbook creates a resource, the script should check to see if the resource already exists before attempting to create it. Here's a basic example.
62
64
@@ -77,7 +79,7 @@ else
77
79
}
78
80
```
79
81
80
-
###Supporting time-dependent scripts
82
+
## Supporting time-dependent scripts
81
83
82
84
Your runbooks must be robust and capable of handling transient errors that can cause them to restart or fail. If a runbook fails, Azure Automation retries it.
83
85
@@ -86,11 +88,11 @@ If your runbook normally runs within a time constraint, have the script implemen
86
88
> [!NOTE]
87
89
> The local time on the Azure sandbox process is set to UTC. Calculations for date and time in your runbooks must take this fact into consideration.
88
90
89
-
###Tracking progress
91
+
## Tracking progress
90
92
91
93
It's a good practice to author your runbooks to be modular in nature, with logic that can be reused and restarted easily. Tracking progress in a runbook is a good way to ensure that the runbook logic executes correctly if there are issues. It's possible to track the progress of a runbook by using an external source, such as a storage account, a database, or shared files. You can create logic in your runbook to first check the state of the last action taken. Then, based on the result of the check, the logic can either skip or continue specific tasks in the runbook.
92
94
93
-
###Preventing concurrent jobs
95
+
## Preventing concurrent jobs
94
96
95
97
Some runbooks behave strangely if they run across multiple jobs at the same time. In this case, it's important for a runbook to implement logic to determine if there is already a running job. Here's a basic example.
To deal with multiple subscriptions, your runbook must use the [Disable-AzContextAutosave](https://docs.microsoft.com/powershell/module/Az.Accounts/Disable-AzContextAutosave?view=azps-3.5.0) cmdlet. This cmdlet ensures that the authentication context isn't retrieved from another runbook running in the same sandbox. The runbook also uses the`AzContext` parameter on the Az module cmdlets and passes it the proper context.
126
128
@@ -147,11 +149,11 @@ Start-AzAutomationRunbook `
147
149
-DefaultProfile $context
148
150
```
149
151
150
-
###Handling exceptions
152
+
## Handling exceptions
151
153
152
-
This section describes some ways to handle exceptions or intermittent issues in your runbooks.
154
+
This section describes some ways to handle exceptions or intermittent issues in your runbooks. An example is a WebSocket exception. Correct exception handling prevents transient network failures from causing your runbooks to fail.
153
155
154
-
####ErrorActionPreference
156
+
### ErrorActionPreference
155
157
156
158
The [ErrorActionPreference](/powershell/module/microsoft.powershell.core/about/about_preference_variables#erroractionpreference) variable determines how PowerShell responds to a non-terminating error. Terminating errors always terminate and are not affected by `ErrorActionPreference`.
[Try Catch Finally](/powershell/module/microsoft.powershell.core/about/about_try_catch_finally) is used in PowerShell scripts to handle terminating errors. The script can use this mechanism to catch specific exceptions or general exceptions. The `catch` statement should be used to track or try to handle errors. The following example tries to download a file that does not exist. It catches the `System.Net.WebException` exception and returns the last value for any other exception.
169
171
@@ -183,7 +185,7 @@ catch
183
185
}
184
186
```
185
187
186
-
####Throw
188
+
### Throw
187
189
188
190
[Throw](/powershell/module/microsoft.powershell.core/about/about_throw) can be used to generate a terminating error. This mechanism can be useful when defining your own logic in a runbook. If the script meets a criterion that should stop it, it can use the `throw` statement to stop. The following example uses this statement to show a required function parameter.
189
191
@@ -195,11 +197,11 @@ function Get-ContosoFiles
195
197
}
196
198
```
197
199
198
-
###Using executables or calling processes
200
+
## Using executables or calling processes
199
201
200
202
Runbooks that run in Azure sandboxes don't support calling processes, such as executables (**.exe** files) or subprocesses. The reason for this is that an Azure sandbox is a shared process run in a container that might not be able to access all the underlying APIs. For scenarios requiring third-party software or calls to subprocesses, you should execute a runbook on a [Hybrid Runbook Worker](automation-hybrid-runbook-worker.md).
201
203
202
-
###Accessing device and application characteristics
204
+
## Accessing device and application characteristics
203
205
204
206
Runbook jobs that run in Azure sandboxes can't access any device or application characteristics. The most common API used to query performance metrics on Windows is WMI, with some of the common metrics being memory and CPU usage. However, it doesn't matter what API is used, as jobs running in the cloud can't access the Microsoft implementation of Web-Based Enterprise Management (WBEM). This platform is built on the Common Information Model (CIM), providing the industry standards for defining device and application characteristics.
Copy file name to clipboardExpand all lines: articles/automation/troubleshoot/runbooks.md
+8-11Lines changed: 8 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -175,11 +175,11 @@ At line:16 char:1
175
175
176
176
### Cause
177
177
178
-
This error is caused by using both AzureRM and Az module cmdlets in a runbook. It occurs when you import the Az module before importing the AzureRM module.
178
+
This error is probably caused by using an incomplete migration from AzureRM to Az modules in your runbook. This can cause Azure Automation to start a runbook job using only AzureRM modules, then start another job using only Az modules, leading to a sandbox crash.
179
179
180
180
### Resolution
181
181
182
-
Az and AzureRM cmdlets can't be imported and used in the same runbook. To learn more about Az cmdlets in Azure Automation, see [Manage modules in Azure Automation](../shared-resources/modules.md).
182
+
We don't recommend the use of Az and AzureRM cmdlets in the same runbook. To learn more about the correct use of these modules, see [Migrating to Az modules](../shared-resources/modules.md#migrating-to-az-modules).
183
183
184
184
## <aname="task-was-cancelled"></a>Scenario: The runbook fails with the error: A task was canceled
185
185
@@ -576,7 +576,7 @@ There are two ways to resolve this error.
576
576
* Instead of using [Start-Job](https://docs.microsoft.com/powershell/module/microsoft.powershell.core/start-job?view=powershell-7), use [Start-AzAutomationRunbook](https://docs.microsoft.com/powershell/module/az.automation/start-azautomationrunbook?view=azps-3.7.0) to start the runbook.
577
577
* Try running the runbook on a Hybrid Runbook Worker.
578
578
579
-
To learn more about this behavior and other behaviors of Azure Automation runbooks, see [Runbook behavior](../automation-runbook-execution.md#runbook-behavior).
579
+
To learn more about this behavior and other behaviors of Azure Automation runbooks, see [Runbook execution in Azure Automation](../automation-runbook-execution.md).
580
580
581
581
## Scenario: Linux Hybrid Runbook Worker receives a prompt for a password when signing a runbook
582
582
@@ -640,11 +640,11 @@ Possible causes for this issue:
640
640
641
641
#### Not using Run As account
642
642
643
-
Follow steps at [Step 5 - Add authentication to manage Azure resources](https://docs.microsoft.com/azure/automation/automation-first-runbook-textual-powershell#add-authentication-to-manage-azure-resources) to ensure that you are using a Run As account to access Key Vault.
643
+
Follow [Step 5 - Add authentication to manage Azure resources](https://docs.microsoft.com/azure/automation/automation-first-runbook-textual-powershell#add-authentication-to-manage-azure-resources) to ensure that you are using a Run As account to access Key Vault.
644
644
645
645
#### Insufficient permissions
646
646
647
-
Follow steps at [Add permissions to Key Vault](https://docs.microsoft.com/azure/automation/manage-runas-account#add-permissions-to-key-vault) to ensure that your Run As account has sufficient permissions to access Key Vault.
647
+
[Add permissions to Key Vault](https://docs.microsoft.com/azure/automation/manage-runas-account#add-permissions-to-key-vault) to ensure that your Run As account has sufficient permissions to access Key Vault.
648
648
649
649
## <aname="other"></a>My problem isn't listed above
650
650
@@ -664,7 +664,7 @@ For help with passing parameters into webhooks, see [Start a runbook from a webh
664
664
665
665
### Issues using Az modules
666
666
667
-
Using Az modules and AzureRM modules in the same Automation account is not supported. See [Az modules in runbooks](https://docs.microsoft.com/azure/automation/az-modules) for more details.
667
+
Using an incomplete migration of your runbook modules from AzureRM to Az can cause sandbox crashes and runbook failures. See [Using modules in your runbooks](../automation-runbook-execution.md#using-modules-in-your-runbooks).
668
668
669
669
### Inconsistent behavior in runbooks
670
670
@@ -683,10 +683,6 @@ Run As accounts might not have the same permissions against Azure resources as y
683
683
684
684
For help with passing parameters into webhooks, see [Start a runbook from a webhook](https://docs.microsoft.com/azure/automation/automation-webhooks#parameters-used-when-the-webhook-starts-a-runbook).
685
685
686
-
### Using Az modules
687
-
688
-
Using Az modules and AzureRM modules in the same Automation account is not supported. See [Az modules in runbooks](https://docs.microsoft.com/azure/automation/az-modules).
689
-
690
686
### Using self-signed certificates
691
687
692
688
To use self-signed certificates, see [Creating a new certificate](https://docs.microsoft.com/azure/automation/shared-resources/certificates#creating-a-new-certificate).
@@ -695,8 +691,9 @@ To use self-signed certificates, see [Creating a new certificate](https://docs.m
695
691
696
692
The Azure sandbox prevents access to all out-of-process COM servers. For example, a sandboxed application or runbook can't call into Windows Management Instrumentation (WMI), or into the Windows Installer service (msiserver.exe). For details about the use of the sandbox, see [Runbook execution in Azure Automation](https://docs.microsoft.com/azure/automation/automation-runbook-execution).
697
693
698
-
## Recommended Documents
694
+
## Recommended documents
699
695
696
+
*[Runbook execution in Azure Automation](../automation-runbook-execution.md)
700
697
*[Starting a runbook in Azure Automation](https://docs.microsoft.com/azure/automation/automation-starting-a-runbook)
701
698
*[Runbook execution in Azure Automation](https://docs.microsoft.com/azure/automation/automation-runbook-execution)
0 commit comments