Skip to main content

Create - Desktop Shortcut

Summary

This document describes how to create a shortcut in the Public Desktop folder.

Sample Run

Sample Run Image 1

To add a desktop shortcut for https://chatgpt.com/:

Sample Run Image 2

Select Run Now and click on Run Task:

Sample Run Image 3

Dependencies

New-DesktopUriShortcut

User Parameters

NameExampleRequiredDescription
TargetUrihttps://www.google.com/TrueThe target path of the shortcut. This can be a local or web URI. Must begin with '<DRIVE_LETTER>:/', 'Https://', or 'http://'
ShortcutNameGoogleFalseThe optional name of the shortcut being set. If not provided, the file name or DnsSafeHost property will be used as the shortcut name.
IconLocation--FalseOptionally set an *.ico file as the shortcut icon.

User Parameters Image

Implementation

Create a new Script Editor style script in the system to implement this task.

Implementation Image 1

Implementation Image 2

Name: Create - Desktop Shortcut
Description: Creates a shortcut in the Public Desktop folder.
Category: Management

Implementation Image 3

Parameters

Add a new parameter by clicking the Add Parameter button present at the top-right corner of the screen.

Parameters Image 1

This screen will appear.

Parameters Image 2

TargetUri

  • Set TargetUri in the Parameter Name field.
  • Select Text String from the Parameter Type dropdown menu.
  • Toggle ON the Required Field button.
  • Click the Save button.

TargetUri Image

Click the Confirm button to save the parameter.

TargetUri Confirm Image

ShortcutName

  • Set ShortcutName in the Parameter Name field.
  • Select Text String from the Parameter Type dropdown menu.
  • Click the Save button.

ShortcutName Image

Click the Confirm button to save the parameter.

ShortcutName Confirm Image

IconLocation

  • Set IconLocation in the Parameter Name field.
  • Select Text String from the Parameter Type dropdown menu.
  • Click the Save button.

IconLocation Image

Click the Confirm button to save the parameter.

IconLocation Confirm Image

Once all the parameters are created, it should look like this:

Parameters Created Image

Proceed with the following steps to create a task.

Task

Navigate to the Script Editor section and start by adding a row. You can do this by clicking the Add Row button at the bottom of the script page.

Task Image

A blank function will appear.

Task Blank Function Image

Row 1 Function: PowerShell Script

Search and select the PowerShell Script function.

PowerShell Script Image

The following function will pop up on the screen:

PowerShell Script Popup Image

Copy the below PowerShell commands and paste them in the PowerShell Script Editor box:

# # Parameters and Globals
# # Parameters and Globals # # Be sure that the name of the hashtable property matches the name of the parameter of the script that you are calling.

$TargetUri = '@TargetUri@'
$ShortcutName = '@ShortcutName@'
$IconLocation = '@IconLocation@'
$Parameters = @{}

if (( $IconLocation -match '\.ico$') )
{$Parameters['IconLocation'] = $IconLocation}

if ($TargetUri -match ':') {
$Parameters['TargetUri'] = $TargetUri
} else {
throw 'Invalid Target'}

$Parameters['ShortcutName'] = $ShortcutName

#region Setup - Variables
$ProjectName = 'New-DesktopUriShortcut'
[Net.ServicePointManager]::SecurityProtocol = [enum]::ToObject([Net.SecurityProtocolType], 3072)
$BaseURL = 'https://file.provaltech.com/repo'
$PS1URL = "$BaseURL/script/$ProjectName.ps1"
$WorkingDirectory = "C:\ProgramData\_automation\script\$ProjectName"
$PS1Path = "$WorkingDirectory\$ProjectName.ps1"
$Workingpath = $WorkingDirectory
$LogPath = "$WorkingDirectory\$ProjectName-log.txt"
$ErrorLogPath = "$WorkingDirectory\$ProjectName-Error.txt"
#endregion

#region Setup - Folder Structure
New-Item -Path $WorkingDirectory -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
$response = Invoke-WebRequest -Uri $PS1URL -UseBasicParsing
if (($response.StatusCode -ne 200) -and (!(Test-Path -Path $PS1Path))) {
throw "No pre-downloaded script exists and the script '$PS1URL' failed to download. Exiting."
} elseif ($response.StatusCode -eq 200) {
Remove-Item -Path $PS1Path -ErrorAction SilentlyContinue
[System.IO.File]::WriteAllLines($PS1Path, $response.Content)
}
if (!(Test-Path -Path $PS1Path)) {
throw 'An error occurred and the script was unable to be downloaded. Exiting.'
}
#endregion
#region Execution
if ($Parameters) {
& $PS1Path @Parameters
} else {
& $PS1Path
}
#endregion

if ( !(Test-Path $LogPath) ) {
throw 'PowerShell Failure. A Security application seems to have restricted the execution of the PowerShell Script.'
}
if ( Test-Path $ErrorLogPath ) {
$ErrorContent = ( Get-Content -Path $ErrorLogPath )
throw $ErrorContent
}
Get-Content -Path $LogPath

PowerShell Script Editor Image

Row 2 Function: Script Log

Add a new row by clicking the Add Row button.

Script Log Image

A blank function will appear.

Script Log Blank Function Image

Search and select the Script Log function.

Script Log Function Image

The following function will pop up on the screen:

Script Log Popup Image

In the script log message, simply type %output% and click the Save button.

Script Log Save Image

Click the Save button at the top-right corner of the screen to save the script.

Script Log Save Confirmation Image

Completed Task

The Script Editor should look like this:

Completed Task Image

Output

  • Script log