Create Shortcuts .lnk or .url Files With PowerShell

Have you ever needed to create shortcuts while scripting. Shortcuts are simply .lnk files with a few details highlighting a few details of the file that you would like to launch. Many people simply copy an already created shortcut. With PowerShell you can actually create a shortcut from scratch by utilizing the New-Object commandlet. Here is the quick run down with explanation.

Step #1: The first step is to create a variable referencing a Wscript.Shell COM Object.

Step #2: The second step is to define the location and name of your shortcut. The following example will add the shortcut to the user’s desktop with a name of Your Shortcut.

Step #3: The third step is to add the target path, any relevant arguments, along with anything else that may be required.

Step #4: The final step is to envoke the Save() method to save your shortcut.

Step #5: As a bonus here is how you would create a Favorite in Windows which is a .url shortcut.

Print Friendly, PDF & Email

6 Comments

  1. Pingback: Create Windows Shortcuts or Favorites With PowerShell » PowerShell.org

  2. Pingback: Group wall post by Rajen Sathish | SCCM Architects

  3. Nic

    Hello i was wondering if it is possible and how one whould command the specified url to be opened in a non default browser.
    Since sertain users need specific websites to open in specific browsers.

    The noobs thing the website is a program and refuze to use favorites.

  4. Kumar

    Hi i am getting below error

    Error: Unable to save shortcut “\\sites\global\npss\Dev MC Order Boards and Shelf Tags\Grocery\SP\PDFs\Store PDFs\ARR_Arroyo\VINEGAR_08FT_260A300B.lnk”.

    i am able to create shortcut in my local but i am not able to create on sharepoint server . could you please tell me the problem . and i need solution for this.

    1. Steve Parankewich

      It looks like a permissions error trying to save it to the UNC path. Try doing a simple copy of the file to the location from PowerShell before proceeding to do the creation of a new link.

Leave a Reply

Your email address will not be published. Required fields are marked *