# Script to Create a New Folder and Add Shortcut on Windows

Saving too many files on your desktop may slow down the system and make it harder to organize files. In addition, files on the desktop are not as secure as the files in libraries like ‘My Documents’ when you use System Restore or run file-based backup programs. Therefore, it is recommended to create shortcuts on your desktop as a quick way to access files stored on your hard drive. With Hexnode, IT admins can seamlessly execute [custom scripts](https://www.hexnode.com/mobile-device-management/help/executing-custom-scripts-for-windows/) remotely on Windows devices.

 Note: 
**Supported Versions**:

The scripts given below will be supported on the following versions:

- Windows 10 v1607+ (Pro, Enterprise, Education)
- Windows 11 (Pro, Enterprise, Education)

 

 Disclaimer:The sample scripts provided below are adapted from third-party open-source sites.

 

PowerShell Script
-----------------

Sample script

\# Set the folder path $folderPath = "Enter folder path" # For example: "C:\\EpicFolder" # Create the folder New-Item -Path $folderPath -ItemType Directory -Force # Set the Desktop path where the shortcut should be created $desktopPath = "Enter the path to add shortcut" # For example: "C:\\Users\\Admin\\Desktop" # Set the shortcut name (include .lnk extension) $shortcutName = "Enter shortcut name" # For example: "EpicFolderShortcut.lnk" # Create the shortcut $wshshell = New-Object -ComObject WScript.Shell $shortcut = $wshshell.CreateShortcut("$desktopPath\\$shortcutName") $shortcut.TargetPath = $folderPath $shortcut.Save() Write-Output "Folder and shortcut created successfully!"

   1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

  \# Set the folder path

$folderPath = "Enter folder path" \# For example: "C:\\EpicFolder"

\# Create the folder

New-Item -Path $folderPath -ItemType Directory -Force

\# Set the Desktop path where the shortcut should be created

$desktopPath = "Enter the path to add shortcut" \# For example: "C:\\Users\\Admin\\Desktop"

\# Set the shortcut name (include .lnk extension)

$shortcutName = "Enter shortcut name" \# For example: "EpicFolderShortcut.lnk"

\# Create the shortcut

$wshshell = New-Object -ComObject WScript.Shell

$shortcut = $wshshell.CreateShortcut("$desktopPath\\$shortcutName")

$shortcut.TargetPath = $folderPath

$shortcut.Save()

Write-Output "Folder and shortcut created successfully!"

   

 

  

![Script to create a new folder and add shortcut on Windows remotely executed successfully from Hexnode.](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2022/03/Folder-created-and-shortcut-added-remotely-on-Windows-with-script--300x149.png)

Provide the folder path to be created, desktop path to add the shortcut, and shortcut name for your folder in the placeholders ***$folderPath***, ***$desktopPath***, ***$shortcutName***.

`$folderPath` – Environment variable where applications look for executables which means it can make or break a system or utility installation.

`New-Item` – Creates files and folders.

`ItemType`– Parameter specifies that the new item is a directory, not a file or other file system object.

`Force` -Parameter lets you create a file in the profile path, even when the directories in the path do not exist.

`New-Object` creates the object and sets each property value and invokes each method.

`ComObject`, or plain COM, increases the range of PowerShell activities.

`WScript.Shell`– Creates an object that is an instance of the Windows shell, allowing you to run commands against the Windows shell.

`WshShell` is a generic name for a powerful object that enables you to query and interact with various aspects of the Windows shell.

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.

 Notes:- The latest version of the Hexnode Agent app should be installed on the device.
- It is recommended to manually validate the script execution on a system before executing the action in bulk.
- Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.