Category filter
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 remotely on Windows devices.
PowerShell Script
|
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!" |

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.