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


Any scripts that either require user interactions or device UI interactions aren’t supported. The device UI interactions may include opening an application, playing a video, so on and so forth.

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.

  1. On your Windows 10 PC, open the Notepad app.
  2. 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.

  3. Save the file with the extension “.ps1” – for PowerShell scripts. Use the extensions “.cmd” or “.bat” for batch scripts.
  4. To run the script,

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

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 in the MDM console.


The supported script file formats: “.bat”, “.cmd”, and “.ps1”.

To upload script file in Hexnode,
  1. On your Hexnode MDM console, navigate to Content.
  2. Choose My Files and click on Add.
  3. Enter an appropriate file name and upload the script file.
  4. Save the file in Hexnode.

Execute Custom Scripts

Once the script is created and uploaded, it can be pushed remotely to deployed devices via Hexnode.


  • Supported on Windows 10 v1709 or later PC’s and tablets.
  • Supported on devices enrolled via Hexnode Installer app with Hexnode Agent 4.2.2 or later.
  • The file name of a script file should not contain values like / : ? \ * | “ [ ] @ ! % ^ and #.

To execute a custom script on Windows,
  1. On your Hexnode portal, navigate to Manage > Devices.
  2. Select the Windows PC’s or tablets to which the script is to be deployed.
  3. Click Actions > Execute Custom Script.
  4. Choose the platform as Windows.
  5. 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.
  6. The Script name filed will be auto-populated with the name of the script file.
  7. 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 MDM. Add spaces between arguments if you are entering more than one argument to a single script file.
  8. Click on Execute.


The following wildcards can be used to pass Arguments to the script:
%devicename%, %model%, %serialnumber%, %imei%, %osname%, %osversion%, %deviceid%, %iccid%, %phonenumber%, %wifimacaddress%, %name%, %email%, %username%, %domain%, %netbiosname%, %ssid%, %assettag%, %department%, %devicenotes%, %userPrincipalName%, %alternateemail%, and %newline%.

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 is 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.
Custom device script for Windows