Skip to main content

New-DesktopUriShortcut

Description

This guide explains how to create a shortcut in the Public Desktop folder using PowerShell.

Requirements

  • Windows OS
  • PowerShell 5 or higher

Usage

  1. Uses WScriptShell to create a shell shortcut in the $env:PUBLIC\Desktop folder.
  2. Gathers the site favicon if a website is provided as the TargetUri.
  3. Sets the shortcut name to the file or website name if not explicitly provided.
.\New-DesktopUriShortcut.ps1 -TargetUri 'C:\Users\Test.docx' -ShortcutName 'Test Document'

Creates a shortcut to the local file C:\Users\Test.docx with the name 'Test Document'.

.\New-DesktopUriShortcut.ps1 -TargetUri 'https://www.google.com' -ShortcutName 'Google'

Creates a shortcut to a web link on the desktop.

Parameters

ParameterRequiredTypeDescription
TargetUriTrueStringThe target path of the shortcut. This can be a local or web URI. Must begin with '\\<DRIVE_LETTER>:\', 'https://', or 'http://'.
ShortcutNameFalseStringThe optional name of the shortcut. If not provided, the file name or DnsSafeHost property will be used as the shortcut name.
IconLocationFalseStringOptionally set an .ico file as the shortcut icon.

Output

  • $env:PUBLIC\Desktop\link.lnk
  • $env:PUBLIC\Pictures\icon.ico
  • New-DesktopUriShortcut-log.txt
  • New-DesktopUriShortcut-error.txt