Category filter
Script to create a new folder if it doesn’t exist on Windows
A system admin might need to create new folders on employee devices to keep things organized. Doing this manually on each device would be a hassle, especially if the company has numerous endpoints deployed across the globe. This doc assists you on how to remotely create a new folder on Windows devices if it doesn’t already exist by executing custom scripts via Hexnode UEM.
Batch Script
|
1 2 3 4 5 6 7 8 9 |
@echo off cls if not exist "enter_folder_path" ( mkdir "enter_folder_path" echo Folder created. ) else ( echo Folder already exists! ) |
For example: To create a folder named ‘FolderA’ in the Desktop of the user Deborah, replace enter_folder_path with C:\Users\Deborah\Desktop\FolderA\
Remember to put a backslash after the folder name; else, it will search for a file rather than a folder.
PowerShell Script
|
1 2 3 4 5 6 7 8 9 10 |
$folderName = "enter_folder_name_here" $Path = "enter_folder_path" + $folderName if (!(Test-Path $Path)) { New-Item -ItemType Directory -Path $Path -Force Write-Output "Folder created." } else { Write-Output "Folder already exists!" } |

To create a folder named ‘FolderA’ in the Desktop of the user Deborah, replace enter_folder_name_here with FolderA and replace enter_folder_path with C:\Users\Deborah\
If you want to create a folder with the folder name as that particular day’s date, replace enter_folder_name_here with (Get-Date).tostring(“dd-MM-yyyy”) without the double-inverted commas.
i.e., $folderName = (Get-Date).tostring(“dd-MM-yyyy”)
How to View Script Output in Hexnode
To review the execution results, navigate to the Action History tab of the specific device in your Hexnode UEM portal. Locate the script entry in the Subject column and click the Show Output button next to the status field to view the returned data.