Skip to content

Commit 8d914ca

Browse files
authored
Merge pull request #112667 from BethWilke/branch203
Fixing tasks 1704269, 1711077
2 parents d17d8bf + 2c4b58f commit 8d914ca

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

articles/automation/automation-runbook-execution.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ The following table lists some runbook execution tasks with the recommended exec
5454
|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.|
5555
|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. |
5656

57-
## Runbook behavior
57+
## Using modules in your runbooks
5858

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
6062

6163
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.
6264

@@ -77,7 +79,7 @@ else
7779
}
7880
```
7981

80-
### Supporting time-dependent scripts
82+
## Supporting time-dependent scripts
8183

8284
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.
8385

@@ -86,11 +88,11 @@ If your runbook normally runs within a time constraint, have the script implemen
8688
> [!NOTE]
8789
> 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.
8890
89-
### Tracking progress
91+
## Tracking progress
9092

9193
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.
9294

93-
### Preventing concurrent jobs
95+
## Preventing concurrent jobs
9496

9597
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.
9698

@@ -120,7 +122,7 @@ If (($jobs.status -contains "Running" -And $runningCount -gt 1 ) -Or ($jobs.Stat
120122
}
121123
```
122124

123-
### Working with multiple subscriptions
125+
## Working with multiple subscriptions
124126

125127
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.
126128

@@ -147,11 +149,11 @@ Start-AzAutomationRunbook `
147149
-DefaultProfile $context
148150
```
149151

150-
### Handling exceptions
152+
## Handling exceptions
151153

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.
153155

154-
#### ErrorActionPreference
156+
### ErrorActionPreference
155157

156158
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`.
157159

@@ -163,7 +165,7 @@ Get-ChildItem -path nofile.txt
163165
Write-Output "This message will not show"
164166
```
165167

166-
#### Try Catch Finally
168+
### Try Catch Finally
167169

168170
[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.
169171

@@ -183,7 +185,7 @@ catch
183185
}
184186
```
185187

186-
#### Throw
188+
### Throw
187189

188190
[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.
189191

@@ -195,11 +197,11 @@ function Get-ContosoFiles
195197
}
196198
```
197199

198-
### Using executables or calling processes
200+
## Using executables or calling processes
199201

200202
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).
201203

202-
### Accessing device and application characteristics
204+
## Accessing device and application characteristics
203205

204206
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.
205207

articles/automation/troubleshoot/runbooks.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ At line:16 char:1
175175

176176
### Cause
177177

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.
179179

180180
### Resolution
181181

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).
183183

184184
## <a name="task-was-cancelled"></a>Scenario: The runbook fails with the error: A task was canceled
185185

@@ -576,7 +576,7 @@ There are two ways to resolve this error.
576576
* 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.
577577
* Try running the runbook on a Hybrid Runbook Worker.
578578

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).
580580

581581
## Scenario: Linux Hybrid Runbook Worker receives a prompt for a password when signing a runbook
582582

@@ -640,11 +640,11 @@ Possible causes for this issue:
640640

641641
#### Not using Run As account
642642

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.
644644

645645
#### Insufficient permissions
646646

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.
648648

649649
## <a name="other"></a>My problem isn't listed above
650650

@@ -664,7 +664,7 @@ For help with passing parameters into webhooks, see [Start a runbook from a webh
664664

665665
### Issues using Az modules
666666

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).
668668

669669
### Inconsistent behavior in runbooks
670670

@@ -683,10 +683,6 @@ Run As accounts might not have the same permissions against Azure resources as y
683683

684684
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).
685685

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-
690686
### Using self-signed certificates
691687

692688
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
695691

696692
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).
697693

698-
## Recommended Documents
694+
## Recommended documents
699695

696+
* [Runbook execution in Azure Automation](../automation-runbook-execution.md)
700697
* [Starting a runbook in Azure Automation](https://docs.microsoft.com/azure/automation/automation-starting-a-runbook)
701698
* [Runbook execution in Azure Automation](https://docs.microsoft.com/azure/automation/automation-runbook-execution)
702699

0 commit comments

Comments
 (0)