How to Create a Shortcut to a Folder Using PowerShell?

Recently, someone asked about creating a shortcut to a folder. PowerShell is perfect for this kind of requirement. In this tutorial, I will explain how to create a shortcut to a folder using PowerShell.

Note: You should have administrative privileges in the system where you want to create a shortcut.

Create a Shortcut to a Folder Using PowerShell

Now, let me show you step-by-step how to create a shortcut to a folder using PowerShell.

1. Open PowerShell

First, open PowerShell with administrative privileges, which is important. You can do this by searching for “PowerShell” in the Start menu, right-clicking on “Windows PowerShell,” and selecting “Run as administrator.”

2. Define the Target Folder and Shortcut Path

Next, you need to define the path to the folder you want to create a shortcut for and the location where you want to place the shortcut. For this example, let’s create a shortcut to the “C:\Projects\USA_Tax_Reports” folder on the desktop.

$targetFolder = "C:\Projects\USA_Tax_Reports"
$shortcutLocation = "$env:UserProfile\Downloads\USA_Tax_Reports.lnk"

Check out Create Local Users in Windows Using PowerShell

3. Create the Shortcut

PowerShell doesn’t have a built-in cmdlet for creating shortcuts, so we need to use COM objects. Here’s the script to create the shortcut:

$WScriptShell = New-Object -ComObject WScript.Shell
$shortcut = $WScriptShell.CreateShortcut($shortcutLocation)
$shortcut.TargetPath = $targetFolder
$shortcut.Save()

This script creates a new shortcut object, sets its target path to the specified folder, and saves the shortcut to the specified location.

Here is the complete script that I executed using Windows PowerShell ISE, and it created the shortcut.

$targetFolder = "C:\Projects\USA_Tax_Reports"
$shortcutLocation = "$env:UserProfile\Downloads\USA_Tax_Reports.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$shortcut = $WScriptShell.CreateShortcut($shortcutLocation)
$shortcut.TargetPath = $targetFolder
$shortcut.Save()
Create a Shortcut to a Folder Using PowerShell

Check out Create Desktop Shortcuts with Custom Icons Using PowerShell

4. Customize the Shortcut (Optional)

You can customize the shortcut by setting additional properties such as the icon, description, and working directory. Here’s an example of how to set these properties:

$shortcut.IconLocation = "C:\Windows\System32\SHELL32.dll,1"  # Change icon
$shortcut.Description = "Shortcut to USA Tax Reports"  # Add description
$shortcut.WorkingDirectory = "C:\Projects"  # Set working directory
$shortcut.Save()

5. Deploying Shortcuts to Multiple Users

If you need to deploy the shortcut to multiple users, you can place it in the “Public Desktop” folder, which is accessible to all users on the system:

$publicDesktop = "C:\Users\Public\Desktop\USA_Tax_Reports.lnk"
$shortcut = $WScriptShell.CreateShortcut($publicDesktop)
$shortcut.TargetPath = $targetFolder
$shortcut.Save()

6. Create Shortcuts to Network Locations

To create shortcuts to network locations, ensure the network path is accessible and use the same script structure. For example:

$targetFolder = "\\NetworkShare\Projects\USA_Tax_Reports"
$shortcutLocation = "$env:UserProfile\Desktop\USA_Tax_Reports.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$shortcut = $WScriptShell.CreateShortcut($shortcutLocation)
$shortcut.TargetPath = $targetFolder
$shortcut.Save()

Read Create a Self-Signed Certificate Using PowerShell

Troubleshooting Common Issues

Now, let me show you some troubleshooting steps to some of the common issues that you might face while executing these commands.

Shortcut Not Appearing

If the shortcut doesn’t appear, ensure that:

  • The target folder path is correct.
  • You have the necessary permissions to create files in the specified location.
  • PowerShell is running with administrative privileges.

Incorrect Icon or Description

If the icon or description isn’t set correctly, double-check the file path and index number for the icon and ensure the description string is properly formatted.

Conclusion

In this tutorial, I explained how to create shortcuts to folders using PowerShell. Following the above steps, you can easily create and customize shortcuts, deploy them across multiple systems, and troubleshoot common issues.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.