Updated on 2024-07-19 GMT+08:00

Script Management

Scenario

On the console, the administrator can remotely run commands based on the created scripts to perform operations on cloud desktops.

By default, running a PowerShell script on Windows desktops is disabled. You need to run commands to enable the function of running a PowerShell script.

Method: Press Win + R on the cloud desktop, enter cmd, and press Enter. On the CLI, run the command Set-ExecutionPolicy RemoteSigned, press Enter, and select y.

Prerequisites

You have obtained the script.

Procedure

Creating a script

  1. Log in to the Workspace console.
  2. In the navigation pane, choose O&M > Script Management.

    The Script Management page is displayed.

  3. Click Create Script in the upper right corner. The Create Script page is displayed.
  4. Configure the script.

    • Script Name: name of the script to be created. The script name must be unique and cannot be empty.
    • Execution Environment: Select Windows Script, Windows PowerShell, or Linux Shell.
    • Description: Enter the description.
    • Script Content: Enter the script content.

  5. Click OK.

Executing a script

  1. Select the script to be executed in the script list.
  2. Click Execute Script above the list. The Execute Script page is displayed.

    • To execute more scripts, click Add Script. In the displayed Add Script dialog box, select the scripts to be executed and click OK.
    • If the selected script does not need to be executed, click Deselect in the Operation column on the Execute Script page.

  3. Select I've checked. No problem. and click Select Object. The Select Target Object page is displayed.
  4. In the Available Objects area, search for the desktop or desktop pool name, select the name, and click Select Execution Configuration.
  5. Select an execution policy, as shown in Table 1.

    Table 1 Execution policies

    Policy Execution Mode

    Parameter Description

    Operation

    Delivery to all

    By default, the script is executed for all selected desktops or desktop pools.

    Set Execution Policy to Delivery to all.

    Gray delivery

    Specified: whether the desktop or desktop pool for which the script is to be executed belongs to the first batch of objects.

    1. If Execution Policy is set to Gray delivery, set Gray Rule to Specified.
    2. Toggle on the First-Batch Execution (Yes/No) switch and select a desktop.
    3. Enter the threshold for stopping executing the next batch if the number of desktops with script execution failure in the first batch is greater than or equal to x.

    Random: The desktop or desktop pool for which the script is to be executed is randomly selected.

    NOTE:

    The gray delivery policy divides desktops into the gray batch and non-gray batch. If the number of desktops with script execution failure in the first batch is greater than or equal to x, scripts will not be executed for desktops in the non-gray batch. If the threshold x is not reached, scripts will be executed for desktops in the non-gray batch.

    1. If Execution Policy is set to Gray delivery, set Gray Rule to Random.
    2. Enter the threshold (x) for the number of desktops that are randomly selected for script execution in the first batch.
    3. Enter the threshold for stopping executing the next batch if the number of desktops with script execution failure in the first batch is greater than or equal to x.

  6. Click Execute.

    You can choose Script Management > Desktop Script Records or Desktop Pool Script Records to check the script execution result.

Editing a script

  1. Click Edit in the Operation column of the desired script. The Edit Script page is displayed.
  2. You can edit the script name, description, and script content.
  3. Click OK.

Copying a script

  1. Click Copy in the Operation column of the desired script. The Copy Script page is displayed.
  2. You can edit the copied script name, execution environment, description, and script content.
  3. Click OK.

Deleting a script

  1. Click Delete in the Operation column of the desired script. The Delete Script page is displayed.
  2. Click OK.

Desktop or desktop pool script records

  1. Under the Desktop Script Records tab, you can use filters, such as Desktop ID, Script ID, Task ID, Execution Status, First-Batch Execution (Yes/No), and Started, to check data of the desktop, such as Desktop Name/ID, Script Name/ID, Task ID, Execution Status, First-Batch Execution (Yes/No), Response, Execution History, Started, and Ended.

    • In the Script Name/ID column, click a script name to check History Script Details.
    • In the Execution Status column, click Retry and click OK to execute the script again.
    • In the Response column, click View to check the response of the desktop to the script execution. You can click Download to download the response.
    • In the Execution History column, click View to check Execution Status, First-Batch Execution (Yes/No), Response, Started, and Ended of the script. Click Retry to execute the script again. Click View in the Response column to check the script. On the page displayed, click Download to download the response of the desktop to the script execution.

  2. Under the Desktop Pool Script Records tab, you can use filters, such as Desktop Pool ID, Script ID, Task ID, Execution Status, and Started, to check data of the desktop pool, such as Desktop Pool Name/ID, Script Name/ID, Task ID, Execution Status, Execution Details, Started, and Ended.

    • In the Script Name/ID column, click a script name to check History Script Details.
    • In the Execution Status column, click Retry and click OK to execute the script again.
    • In the Execution Details column, click View to check data of the desktop pool, such as Desktop Name/ID, Script Name/ID, Task ID, Execution Status, First-Batch Execution (Yes/No), Response, Execution History, Started, and Ended.
      • In the Response column, click View to check the response of the desktop to the script execution. You can click Download to download the response.
      • In the Execution History column, click View to check Execution Status, First-Batch Execution (Yes/No), Response, Started, and Ended of the script. Click Retry to execute the script again. Click View in the Response column to check the script. On the page displayed, click Download to download the response of the desktop to the script execution.