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/pre-post-scripts.md
+39-39Lines changed: 39 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: Configure pre and post-scripts on your Update Management deployment in Azure
3
-
description: This article describes how to configure and manage pre and post-scripts for update deployments
3
+
description: This article describes how to configure and manage pre-scripts and post-scripts for update deployments.
4
4
services: automation
5
5
ms.service: automation
6
6
ms.subservice: update-management
@@ -12,39 +12,39 @@ manager: carmonm
12
12
---
13
13
# Manage pre and post-scripts
14
14
15
-
Pre and post-scripts let you run PowerShell runbooks in your Automation Account before (pre-task) and after (post-task) an update deployment. Pre and post-scripts run in the Azure context and not locally. Pre-scripts run at the beginning of the update deployment. Postscripts run at the end of the deployment and after any reboots that are configured.
15
+
Pre-scripts and post-scripts let you run PowerShell runbooks in your automation account before (pre-task) and after (post-task) an update deployment. Pre and post-scripts run in the Azure context, not locally. Pre-scripts run at the beginning of the update deployment. Post-scripts run at the end of the deployment and after any reboots that are configured.
16
16
17
17
## Runbook requirements
18
18
19
-
For a runbook to be used as a pre or postscript, the runbook needs to be imported into your automation account and published. To learn more about this process, see [Publishing a runbook](manage-runbooks.md#publish-a-runbook).
19
+
For a runbook to be used as a pre or post-script, the runbook must be imported into your automation account and published. To learn more about this process, see [Publish a runbook](manage-runbooks.md#publish-a-runbook).
20
20
21
-
## Using a pre/post script
21
+
## Using a pre-script or post-script
22
22
23
-
To use a pre and or postscript in an Update Deployment, start by creating an Update Deployment. Select **Pre-scripts + PostScripts**. This action opens the **Select Pre-scripts + Post-scripts** page.
23
+
To use a pre-script or post-script in an update deployment, start by creating an update deployment. Select **Pre-scripts + Post-Scripts**. This action opens the **Select Pre-scripts + Post-scripts** page.
Select the script you want to use, in this example, you used the **UpdateManagement-TurnOnVms** runbook. When you select the runbook the **Configure Script** page opens, choose**Pre-Script**. Click **OK** when done.
27
+
Select the script you want to use. In this example, we use the **UpdateManagement-TurnOnVms** runbook. When you select the runbook, the **Configure Script** page opens. Select**Pre-Script**, and then select **OK**.
28
28
29
-
Repeat this process for the **UpdateManagement-TurnOffVms** script. But when choosing the **Script type**, choose**Post-Script**.
29
+
Repeat this process for the **UpdateManagement-TurnOffVms** script. But when you choose the **Script type**, select**Post-Script**.
30
30
31
-
The **Selected items** section now shows both your scripts selected and on is a pre-script and the other is a post-script.
31
+
The **Selected items** section now shows both your scripts selected. One is a pre-script and the other is a post-script.
When your Update Deployment is complete, you can go to **Update deployments** to view the results. As you can see, the status of the pre-script and post-script are provided.
37
+
When your update deployment is complete, you can go to **Update deployments** to view the results. As you can see, the status of the pre-script and post-script is provided.
By clicking into the update deployment run, you're provided additional details to the pre and post-scripts. A link to the script source at the time of the run is provided.
41
+
By selecting the update deployment run, you're shown additional details to the pre and post-scripts. A link to the script source at the time of the run is provided.
42
42
43
43

44
44
45
45
## Passing parameters
46
46
47
-
When you configure pre and post-scripts, you can pass in parameters just like scheduling a runbook. Parameters are defined at the time of update deployment creation. Pre and Post-scripts support the following types:
47
+
When you configure pre and post-scripts, you can pass in parameters just like scheduling a runbook. Parameters are defined at the time of update deployment creation. Pre and post-scripts support the following types:
48
48
49
49
*[char]
50
50
*[byte]
@@ -58,24 +58,24 @@ When you configure pre and post-scripts, you can pass in parameters just like sc
58
58
59
59
If you need another object type, you can cast it to another type with your own logic in the runbook.
60
60
61
-
In addition to your standard runbook parameters, an additional parameter is provided. This parameter is **SoftwareUpdateConfigurationRunContext**. This parameter is a JSON string, and if you define the parameter in your pre or postscript, it's automatically passed in by the update deployment. The parameter contains information about the update deployment, which is a subset of information returned by the [SoftwareUpdateconfigurations API](/rest/api/automation/softwareupdateconfigurations/getbyname#updateconfiguration) The following table shows you the properties that are provided in the variable:
61
+
In addition to your standard runbook parameters, another parameter is provided: **SoftwareUpdateConfigurationRunContext**. This parameter is a JSON string, and if you define the parameter in your pre or post-script, it's automatically passed in by the update deployment. The parameter contains information about the update deployment, which is a subset of information returned by the [SoftwareUpdateconfigurations API](/rest/api/automation/softwareupdateconfigurations/getbyname#updateconfiguration) The following table shows you the properties that are provided in the variable.
|SoftwareUpdateConfigurationName | The name of the Software Update Configuration|
68
+
|SoftwareUpdateConfigurationName | The name of the software update configuration|
69
69
|SoftwareUpdateConfigurationRunId | The unique ID for the run. |
70
-
|SoftwareUpdateConfigurationSettings | A collection of properties related to the Software Update Configuration|
71
-
|SoftwareUpdateConfigurationSettings.operatingSystem | The operating systems targeted for the update deployment |
72
-
|SoftwareUpdateConfigurationSettings.duration | The maximum duration of the update deployment run as `PT[n]H[n]M[n]S` as per ISO8601, also called the "maintenance window"|
73
-
|SoftwareUpdateConfigurationSettings.Windows | A collection of properties related to Windows computers |
74
-
|SoftwareUpdateConfigurationSettings.Windows.excludedKbNumbers | A list of KBs that are excluded from the update deployment |
75
-
|SoftwareUpdateConfigurationSettings.Windows.includedUpdateClassifications | Update classifications selected for the update deployment |
76
-
|SoftwareUpdateConfigurationSettings.Windows.rebootSetting | Reboot settings for the update deployment |
77
-
|azureVirtualMachines | A list of resourceIds for the Azure VMs in the update deployment |
78
-
|nonAzureComputerNames|A list of the Non-Azure computers FQDNs in the update deployment|
70
+
|SoftwareUpdateConfigurationSettings | A collection of properties related to the software update configuration.|
71
+
|SoftwareUpdateConfigurationSettings.operatingSystem | The operating systems targeted for the update deployment.|
72
+
|SoftwareUpdateConfigurationSettings.duration | The maximum duration of the update deployment run as `PT[n]H[n]M[n]S` as per ISO8601, also called the *maintenance window*.|
73
+
|SoftwareUpdateConfigurationSettings.Windows | A collection of properties related to Windows computers.|
74
+
|SoftwareUpdateConfigurationSettings.Windows.excludedKbNumbers | A list of KBs that are excluded from the update deployment.|
75
+
|SoftwareUpdateConfigurationSettings.Windows.includedUpdateClassifications | Update classifications selected for the update deployment.|
76
+
|SoftwareUpdateConfigurationSettings.Windows.rebootSetting | Reboot settings for the update deployment.|
77
+
|azureVirtualMachines | A list of resourceIds for the Azure VMs in the update deployment.|
78
+
|nonAzureComputerNames|A list of the non-Azure computers FQDNs in the update deployment.|
79
79
80
80
The following example is a JSON string passed in to the **SoftwareUpdateConfigurationRunContext** parameter:
81
81
@@ -107,15 +107,15 @@ The following example is a JSON string passed in to the **SoftwareUpdateConfigur
107
107
}
108
108
```
109
109
110
-
A full example with all properties can be found at: [Software Update Configurations - Get By Name](/rest/api/automation/softwareupdateconfigurations/getbyname#examples)
110
+
A full example with all properties can be found at: [Software update configurations – Get by name](/rest/api/automation/softwareupdateconfigurations/getbyname#examples).
111
111
112
112
> [!NOTE]
113
-
> The `SoftwareUpdateConfigurationRunContext` object can contain duplicate entries for machines. This can cause Pre and Post scripts to run multiple times on the same machine. To workaround this behavior, use `Sort-Object -Unique` to select only unique VM names in your script.
113
+
> The `SoftwareUpdateConfigurationRunContext` object can contain duplicate entries for machines. This can cause pre and post-scripts to run multiple times on the same machine. To work around this behavior, use `Sort-Object -Unique` to select only unique VM names in your script.
114
114
115
115
116
116
## Stopping a deployment
117
117
118
-
If you want to stop a deployment based on a pre-script, you must [throw](automation-runbook-execution.md#throw) an exception. If you don't throw an exception, the deployment and Post script will still run. The code snippet below shows how to throw an exception.
118
+
If you want to stop a deployment based on a pre-script, you must [throw](automation-runbook-execution.md#throw) an exception. If you don't, the deployment and post-script will still run. The following code snippet shows how to throw an exception.
119
119
120
120
```powershell
121
121
#In this case, we want to terminate the patch job if any run fails.
@@ -132,11 +132,11 @@ foreach($summary in $finalStatus)
132
132
133
133
## Samples
134
134
135
-
Samples for pre and post-scripts can be found in the [Script Center Gallery](https://gallery.technet.microsoft.com/scriptcenter/site/search?f%5B0%5D.Type=RootCategory&f%5B0%5D.Value=WindowsAzure&f%5B0%5D.Text=Windows%20Azure&f%5B1%5D.Type=SubCategory&f%5B1%5D.Value=WindowsAzure_automation&f%5B1%5D.Text=Automation&f%5B2%5D.Type=SearchText&f%5B2%5D.Value=update%20management&f%5B3%5D.Type=Tag&f%5B3%5D.Value=Patching&f%5B3%5D.Text=Patching&f%5B4%5D.Type=ProgrammingLanguage&f%5B4%5D.Value=PowerShell&f%5B4%5D.Text=PowerShell), [PowerShell Gallery](https://www.powershellgallery.com/packages?q=Tags%3A%22UpdateManagement%22+Tags%3A%22Automation%22), or imported through the Azure portal. To import them through the portal, in your Automation Account, under **Process Automation**, select **Runbooks Gallery**. Use **Update Management** for the filter.
135
+
Samples for pre and post-scripts can be found in the [Script Center Gallery](https://gallery.technet.microsoft.com/scriptcenter/site/search?f%5B0%5D.Type=RootCategory&f%5B0%5D.Value=WindowsAzure&f%5B0%5D.Text=Windows%20Azure&f%5B1%5D.Type=SubCategory&f%5B1%5D.Value=WindowsAzure_automation&f%5B1%5D.Text=Automation&f%5B2%5D.Type=SearchText&f%5B2%5D.Value=update%20management&f%5B3%5D.Type=Tag&f%5B3%5D.Value=Patching&f%5B3%5D.Text=Patching&f%5B4%5D.Type=ProgrammingLanguage&f%5B4%5D.Value=PowerShell&f%5B4%5D.Text=PowerShell), [PowerShell Gallery](https://www.powershellgallery.com/packages?q=Tags%3A%22UpdateManagement%22+Tags%3A%22Automation%22), or you can import them through the Azure portal. To do that, in your Automation Account, under **Process Automation**, select **Runbooks Gallery**. Use **Update Management** for the filter.
Or you can search for them by their script name as seen in the following list:
139
+
Or you can search for them by their script name, as shown in the following list:
140
140
141
141
* Update Management - Turn On VMs
142
142
* Update Management - Turn Off VMs
@@ -145,17 +145,17 @@ Or you can search for them by their script name as seen in the following list:
145
145
* Update Management - Run Script with Run Command
146
146
147
147
> [!IMPORTANT]
148
-
> After you import the runbooks, you must **Publish** them before they can be used. To do that find the runbook in your Automation Account, select **Edit**, and click**Publish**.
148
+
> After you import the runbooks, you must **Publish** them before they can be used. To do that, find the runbook in your automation account, select **Edit**, and select**Publish**.
149
149
150
-
The samples are all based on the basic template that is defined in the following example. This template can be used to create your own runbook to use with pre and post-scripts. The necessary logic for authenticating with Azure and handling the `SoftwareUpdateConfigurationRunContext` parameter are included.
150
+
The samples are all based on the basic template that's defined in the following example. This template can be used to create your own runbook to use with pre and post-scripts. The necessary logic for authenticating with Azure and handling the `SoftwareUpdateConfigurationRunContext` parameter is included.
151
151
152
152
```powershell
153
153
<#
154
154
.SYNOPSIS
155
155
Barebones script for Update Management Pre/Post
156
156
157
157
.DESCRIPTION
158
-
This script is intended to be run as a part of Update Management Pre/Post scripts.
158
+
This script is intended to be run as a part of Update Management pre/post-scripts.
Pre and post-tasks run as a runbook in your Automation Account and not directly on the machines in your deployment. Pre and post-tasks also run in the Azure context and don't have access to Non-Azure machines. The following sections show how you can interact with the machines directly whether they're an Azure VM or a Non-Azure machine:
205
+
Pre and post-script tasks run as a runbook in your automation account and not directly on the machines in your deployment. Pre and post-script tasks also run in the Azure context and don't have access to non-Azure machines. The following sections show how you can interact with the machines directly, whether they're Azure VMs or non-Azure machines.
206
206
207
207
### Interacting with Azure machines
208
208
@@ -211,22 +211,22 @@ Pre and post-tasks are run as runbooks and don't natively run on your Azure VMs
211
211
* A Run As account
212
212
* A runbook you want to run
213
213
214
-
To interact with Azure machines, you should use the [Invoke-AzureRmVMRunCommand](/powershell/module/azurerm.compute/invoke-azurermvmruncommand) cmdlet to interact with your Azure VMs. For an example of how to do this, see the runbook example [Update Management - Run Script with Run Command](https://gallery.technet.microsoft.com/Update-Management-Run-40f470dc).
214
+
To interact with Azure machines, you should use the [Invoke-AzureRmVMRunCommand](/powershell/module/azurerm.compute/invoke-azurermvmruncommand) cmdlet to interact with your Azure VMs. For an example of how to do this, see the runbook example [Update Management - Run script with Run command](https://gallery.technet.microsoft.com/Update-Management-Run-40f470dc).
215
215
216
216
### Interacting with Non-Azure machines
217
217
218
-
Pre and post-tasks run in the Azure context and don't have access to Non-Azure machines. To interact with the Non-Azure machines, you must have the following items:
218
+
Pre and post-script tasks run in the Azure context and don't have access to non-Azure machines. To interact with the non-Azure machines, you must have the following items:
219
219
220
220
* A Run As account
221
221
* Hybrid Runbook Worker installed on the machine
222
222
* A runbook you want to run locally
223
-
*Parent runbook
223
+
*A parent runbook
224
224
225
-
To interact with Non-Azure machines, a parent runbook is run in the Azure context. This runbook calls a child runbook with the [Start-AzureRmAutomationRunbook](/powershell/module/azurerm.automation/start-azurermautomationrunbook) cmdlet. You must specify the `-RunOn` parameter and provide the name of the Hybrid Runbook Worker for the script to run on. For an example, see the runbook example [Update Management - Run Script Locally](https://gallery.technet.microsoft.com/Update-Management-Run-6949cc44).
225
+
To interact with non-Azure machines, a parent runbook is run in the Azure context. This runbook calls a child runbook with the [Start-AzureRmAutomationRunbook](/powershell/module/azurerm.automation/start-azurermautomationrunbook) cmdlet. You must specify the `-RunOn` parameter and provide the name of the Hybrid Runbook Worker for the script to run on. For more info, see the runbook example [Update Management - Run Script Locally](https://gallery.technet.microsoft.com/Update-Management-Run-6949cc44).
226
226
227
227
## Abort patch deployment
228
228
229
-
If your prescript returns an error, you may want to abort your deployment. To do this, you must [throw](/powershell/module/microsoft.powershell.core/about/about_throw) an error in your script for any logic that would constitute a failure.
229
+
If your pre-script returns an error, you might want to abort your deployment. To do that, you must [throw](/powershell/module/microsoft.powershell.core/about/about_throw) an error in your script for any logic that would constitute a failure.
230
230
231
231
```powershell
232
232
if (<My custom error logic>)
@@ -238,11 +238,11 @@ if (<My custom error logic>)
238
238
239
239
## Known issues
240
240
241
-
* You can't pass a boolean, objects, or arrays to parameters when using pre and post-scripts. The runbook will fail. For a complete list of supported types, see [parameters](#passing-parameters).
241
+
* You can't pass a boolean, objects, or arrays to parameters when you're using pre and post-scripts. If you do, the runbook fails. For a complete list of supported types, see [parameters](#passing-parameters).
242
242
243
243
## Next steps
244
244
245
-
Continue to the tutorial to learn how to manage updates for your Windows virtual machines.
245
+
Go on to the following tutorial to learn how to manage updates for your Windows virtual machines:
246
246
247
247
> [!div class="nextstepaction"]
248
248
> [Manage updates and patches for your Azure Windows VMs](automation-tutorial-update-management.md)
0 commit comments