Category filter
Executing custom scripts for Windows
Organizations may sometimes seek the assistance of script commands to execute specific routine and time-consuming operations on the Windows machine that are not natively supported by the UEM platform. A script is a series of commands written in a scripting language that details the operations you want to perform on the machine and automatically execute it on the devices without any manual intervention. These tasks otherwise have to be manually administrated one by one on each device.
For executing custom scripts on Windows machines, create script files with custom configurations that suit your demands and upload the file to Hexnode. Then push the script file to the target devices. However, it is recommended to manually validate the script execution on a single device before associating it with bulk devices. This helps to analyze and remediate the associated issues without heavily impacting business continuity or productivity.
Windows Scripting languages
The Execute Custom Script action for Windows lets IT administrators deploy customized scripts to multiple Windows. Before getting to know how to create and run scripts via Hexnode, it is better to have a basic idea about the scripting languages supported by Hexnode.
Batch
A batch script automates repetitive command sequences in shell environments such as Command Prompt in Windows, Terminal in macOS, or various Unix/Linux shells. These scripts are stored in simple text files with extensions such as .BAT or .CMD. They contain sequences of commands that are executed through the command interpreter (cmd.exe on Windows). Batch scripts control structures like loops and conditionals, support advanced functions and arrays, and can integrate with other languages like Perl. They are commonly used for tasks such as server setup, deployment, and mass program installations. Execution of a batch script is straightforward; it can be done either by clicking the corresponding file present on the device or through the device’s command prompt. However, the full path name is required for execution outside the script’s directory unless it’s included in the system’s path environment.
PowerShell
A PowerShell script is a command-line tool specifically designed for system administration in Windows environments. Like Bash scripting in Linux, it uses cmdlets to manage computers and automate tasks efficiently. PowerShell is built on the .NET Framework, which provides access to various data stores and a rich scripting language. This allows users to perform tasks traditionally done through Graphical User Interfaces (GUIs) and more.
Create and run scripts
Hexnode supports .ps1, .bat and .cmd script files. The PowerShell scripts (.ps1) and batch files (.bat or .cmd) can be created via different code editor tools. However, the easiest way of creating a script file is by using a Notepad editor. Let’s look into how PowerShell and batch script files can be created and executed using Notepad on a Windows machine.
- On your Windows PC, open the Notepad app.
- Enter the commands required for your script in the text file. An example of a PowerShell script and a batch script is as follows.
PowerShell script:
New-Item -Path 'D:\temp\Hexnode Folder' -ItemType Directory
This is a script file for creating a new folder called “Hexnode Folder” in the location D:\temp on the device.
Batch script:
@echo off
echo "Hello">C:\Hexnode.txt
This script will create a new text file named Hexnode in the C-Drive on the device.
- Save the file with the extension “.ps1” – for PowerShell scripts. Use the extensions “.cmd” or “.bat” for batch scripts.
- Open the command prompt and enter the full path of the script in the format c:/scripts/scriptname.ps1. Press the Enter button to run the operation.
To run the script,
Running the script on selected devices manually before bulk deployment enables pre-emptively identifying and removing errors before causing severe business continuity issues.
Upload script to Hexnode
The scripts are used to proactively set up configurations or execute operations on the devices. For deploying these script files to the devices via Hexnode, they have to be first uploaded to the UEM console.
To upload script file in Hexnode,
- On your Hexnode UEM console, navigate to Content.
- Choose My Files and click on Add.
- Enter an appropriate file name and upload the script file.
- Save the file in Hexnode.
How to execute custom scripts for Windows from Hexnode?
Once the script is created and uploaded, it can be pushed remotely to deployed devices via Hexnode.
To execute a custom script on Windows,
- On your Hexnode UEM portal, navigate to Manage > Devices.
- Select the Windows PC’s or tablets to which the script is to be deployed.
- Click Actions > Execute Custom Script.
- Choose the platform as Windows.
- Choose the script file source as either Upload file or Hexnode repository.
- If Upload file is chosen, click on Choose file… corresponding to the Upload File field. Choose a script file that resides on your machine.
- If Hexnode repository is selected, you will be asked to select the previously uploaded script file in the Content tab in Hexnode. You can also generate a script with the help of Hexnode Genie.
- The Script name field will be auto-populated with the name of the script file.
- Enter the Arguments for the chosen script file. Arguments are the variable provided in the command line while executing a script. Such arguments can be remotely deployed to the device via the UEM. Add spaces between arguments if you are entering more than one argument into a single script file.
- Provide a time duration in the Timeout field. If the script execution does not finish within the specified period, it will be forcefully terminated. The minimum time duration is 15 minutes. However, it is recommended that the default value of 30 minutes be left unchanged.
- Click on Execute.
Check Action status
Navigate to the Action History tab of the device to view the script execution status. The Hexnode administrators can check the output of the pushed script file on the device (only if the script file returns an output) by navigating to Manage > Device > the device to which the action is pushed > Action History. Click on Show Output corresponding to the script execution action to view its output.
If the action is successful and the configurations of the script file are correct, then the script will get automatically executed on the device.
The uploaded script file was for creating a new document named “par” in the C-Drive of the device with content 1, 2 and 3, the parameters passed through Hexnode.