Scripted Actions Overview

Scripted Actions Overview

Scripted Actions are PowerShell scripts that run either in the context of a Windows VM or an Azure Automation Account. Scripted Actions can be used to extend and customize the functionality of Nerdio Manager. Nerdio Manager provides several pre-populated variables, such as $VMName, that can be used in the PowerShell code.

Nerdio Manager contains many out-of-the box scripted actions. In addition, scripts can be created and customized by the Nerdio Manager administrators. They can be applied at various stages of the Nerdio Manager automation. For example, when a Virtual Machine is created, shut down, or removed. You can apply an action on a schedule, or to desktop images, and more.

Nerdio Manager uses two types of scripted actions:

Scripted Actions serve as a library of PowerShell scripts that can be run in either Azure or AVD Virtual Machines, as an included step for various tasks performed by Nerdio Manager.

Create a New Scripted Action

To create a new scripted action:

  1. Navigate to Scripted Actions.

  2. Select either Windows scripts or Azure runbooks.

  3. Select Add scripted action.

  4. Enter the following information:

    • Name: Type the name of the script. This name is displayed when you select this action from the list of available scripted actions.

    • Description: Type the script's description.

    • Tags: From the drop-down list, select optional tags for the script. These tags are used for searching and organization.

    • Script Execution Mode: From the drop-down list, select the script's execution mode.

      Note: This parameter determines how Nerdio Manager acts when it passes the scripted action(s) to the VM. Nerdio Manager uses the Azure Custom Script Extension to ultimately execute the PowerShell commands (for more information about Scripted Actions for windows refer to Custom Script for Windows). The extension needs to be installed and removed every time Nerdio Manager executes a Windows Scripted Action. Optionally, PowerShell scripts can be combined and passed in a single run, if they do not interfere with each other, thus saving time.

      • Combined: Marks the script as one that can be combined safely with other scripts. For example, a script that adds a registry value.

      • Individual: A stand-alone script for an action that should be run on its own. For example, a long script with commonly used variable names that may conflict with other scripts, or a script that requires a fresh PowerShell session.

      • Individual with restart: For Windows scripts, run the script in stand-alone mode and perform a restart when complete.

      • Execution Timeout: For Azure runbooks in Individual mode, type the timeout (in minutes) for the scripted action execution.

    • Enable Cloud PC: Optionally for Windows scripts, toggle this option on to create a Cloud PC script policy.

      • Run this script using the logged on credentials: Select this option to run the script with the user's credentials on the client computer. By default, the script runs in system context.

      • Enforce script signature check: Select this option to enforce that the script must be signed by a trusted publisher. By default, no warning or prompt displays and the script runs unblocked.

      • Run script in 64 bit PowerShell Host: Select this option to run the script in a 64-bit PowerShell Host for a 64-bit client architecture.

      • Assign to all users: Select this option to assign the script to all users.

      • Assign to all devices: Select this option to assign the script to all devices.

      • Assign to selected groups: From the drop-down list, select the group(s) to assign this script to.

      • Exclude assignments: From the drop-down list, select the group(s) to exclude this script from.

    • Script: Type the PowerShell command(s) to execute.

      Note: Nerdio Manager allows you to integrate variables into the Azure runbooks scripted actions. See Scripted Actions Azure Runbooks Variables Integration for more information.

      Note: Cmdlets used in this code must be available on the VMs or in the Azure Automation account. If using PowerShell cmdlets from modules not present by default on the Windows VMs or in the Azure Automation account, the modules must first be installed.

      Nerdio provides several pre-populated variables that can be used in the script code. The available variables are:

      • $HostPoolId (Available when the script is associated with a host pool)

      • $HostPoolName (Available when the script is associated with a host pool)

      • $AzureSubscriptionId

      • $AzureSubscriptionName

      • $AzureResourceGroupName

      • $AzureRegionName

      • $AzureVMName (Available when the script is associated with a VM)

      • $ADUsername (if passing AD credentials)

      • $ADPassword (if passing AD credentials)

      • $DesktopUser (Available when the script is associated with a personal host pool)

      Tip: It is recommended to develop code using an IDE such as VSCode or ISE. Then test the PowerShell code on a dedicated development session Host /Azure VM.

  5. Once you have entered all the desired information, select Save & close.

View and Edit Existing Scripted Actions

Nerdio Manager allows you to view or edit existing scripted actions.

To view and edit an existing scripted action:

  1. Navigate to Scripted actions.

  2. Select either Windows Scripts or Azure runbooks.

  3. Locate the scripted action you want to work with and select Edit.

  4. If desired, make the necessary changes and select Save and close.

Clone a Scripted Action

Nerdio Manager allows you to clone a scripted action.

To clone a scripted action:

  1. Navigate to Scripted actions.

  2. Select either Windows Scripts or Azure runbooks.

  3. Locate the scripted action you want to clone, and from the action menu select Clone.

  4. Make all the necessary changes and select Clone.

Scripted Actions Groups

Scripted Actions Groups allows administrators to create script collections and assigns these during standard deployment tasks. See Scripted Actions Groups for details.

Apply Scripted Actions

Scripted Actions can be used as part of these tasks:

  • VM Lifecycle Events: Executed during the provisioning or re-imaging of Session Host VMs, or when a VM is stopped/started. Whenever a session host is created, destroyed, stopped, or started, the scripted action is performed as a final step. For more information about re-imaging the hosts refer to Resize/Re-image a Host Pool.

  • Run Script: Manually run a command against a host pool. This is useful if you need to change all the session hosts without fully re-imaging them (for example, a script to change a registry key). For more information refer to Run Bulk Host Scripted Actions.

To apply a configured scripted action to AVD host VM lifecycle events:

  1. Locate the host pool you wish to work with.

  2. From the action menu, select PropertiesVM Deployment.

  3. Toggle on the desired Run scripted actions when... options.

  4. For each option, enter the following information:

    • Script: From the drop-down list, select the script to execute.

    • Scripted actions input parameters: If necessary, provide the required parameters.

    • Pass AD credentials: Select this option to pass AD credentials to the script as variables.

    • AD Credentials: From the drop-down list, select the AD credentials to pass.

  5. Once you have entered all the desired information, select Save & close.

    The scripted actions are added to the list of scripted actions for this host pool.

Warning: For some automations, the necessary actions to take must be done in the context of Azure, outside of the VM itself. While these commands could be run on the session host VM with the Azure PowerShell module installed, running scripts on session hosts that target Azure are less efficient and can be unreliable. Azure Automation allows for consistent execution, and allows for the Nerdio Manager to run the scripts as itself easily. Some scripts even require the VM to be restarted or shutdown, which means it could not be run on the session host VM regardless.

For information about troubleshooting the Azure scripts, refer to Troubleshoot Scripts.

To run a scripted action on the Host Pool using the Run Script option:

  1. Locate the host pool you wish to work with.

  2. From the action menu, select Hosts > Run script.

  3. Enter the following information:

    • Run the following scripted actions on all VMs in ...: From the drop-down list, select the scripted actions that you want to apply.

    • Scripted actions input parameters: If necessary, provide the required parameters.

    • Pass AD credentials: Select this option to pass AD credentials.
    • AD Credentials: From the drop-down list, select the AD credentials to pass.

    • Restart VMs after scripted action: Select this option to restart the VMs after script execution. It is preferable to use this option instead of using any PowerShell restart commands as Custom Script extension fails if the script restarts the computer.

    • Process hosts in groups of: Type the number of concurrent actions to execute during this bulk operation

    • Number of failures before aborting: Type the number of failures that causes the process to stop.

    • Schedule: Toggle on the Schedule, and enter the schedule information, to enable running the script per a schedule.

    • Messaging: Toggle on the Messaging to send messages to active users.

      • Delay: From the drop-down list, select the number of minutes to wait after sending the message before starting the process.

      • Message: Type the message you want to send to the users.

  4. Once you have entered all the desired information, select Save & close.

Related Topics

Resize/Re-image a Host Pool

Run Bulk Host Scripted Actions

Scripted Actions for Windows Scripts

Scripted Actions for Azure Runbooks

Troubleshoot Scripts

Was this article helpful?

0 out of 0 found this helpful
Have more questions? Submit a request

Comments (0 comments)

Article is closed for comments.