Skip to main content

Set-Shortcut

SYNOPSIS

Modifies a .lnk or .url type shortcut

SYNTAX

Default (Default)

Set-Shortcut [-Path] <String> [-TargetPath <String>] [-Arguments <String>] [-IconLocation <String>]
[-IconIndex <String>] [-Description <String>] [-WorkingDirectory <String>] [-WindowStyle <String>]
[-RunAsAdmin <Boolean>] [-Hotkey <String>] [-ContinueOnError <Boolean>] [<CommonParameters>]

Pipeline

Set-Shortcut [-PathHash] <Hashtable> [-TargetPath <String>] [-Arguments <String>] [-IconLocation <String>]
[-IconIndex <String>] [-Description <String>] [-WorkingDirectory <String>] [-WindowStyle <String>]
[-RunAsAdmin <Boolean>] [-Hotkey <String>] [-ContinueOnError <Boolean>] [<CommonParameters>]

DESCRIPTION

Modifies a shortcut - .lnk or .url file, with configurable options.

Only specify the parameters that you want to change.

EXAMPLES

EXAMPLE 1

Set-Shortcut -Path "$envProgramData\Microsoft\Windows\Start Menu\My Shortcut.lnk" -TargetPath "$envWinDir\System32\notepad.exe" -IconLocation "$envWinDir\System32\notepad.exe" -IconIndex 0 -Description 'Notepad' -WorkingDirectory "$envHomeDrive\$envHomePath"

PARAMETERS

-Path

Path to the shortcut to be changed

Type: String
Parameter Sets: Default
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-PathHash

{{ Fill PathHash Description }}

Type: Hashtable
Parameter Sets: Pipeline
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-TargetPath

Changes target path or URL that the shortcut launches

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Arguments

Changes Arguments to be passed to the target path

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-IconLocation

Changes location of the icon used for the shortcut

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-IconIndex

Change the index of the icon. Executables, DLLs, ICO files with multiple icons need the icon index to be specified. This parameter is an Integer. The first index is 0.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Description

Changes description of the shortcut

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-WorkingDirectory

Changes Working Directory to be used for the target path

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-WindowStyle

Changes the Windows style of the application. Options: Normal, Maximized, Minimized, DontChange. Default is: DontChange.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: DontChange
Accept pipeline input: False
Accept wildcard characters: False

-RunAsAdmin

Set shortcut to run program as administrator. This option will prompt user to elevate when executing shortcut. If not specified or set to $null, the flag will not be changed.

Type: Boolean
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Hotkey

Changes the Hotkey to launch the shortcut, e.g. "CTRL+SHIFT+F"

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ContinueOnError

Continue if an error is encountered. Default is: $true.

Type: Boolean
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: True
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

PSOjbect

Path to the shortcut to be changed or a hashtable of parameters to be changed

OUTPUTS

None

This function does not generate any output.

NOTES

Url shortcuts only support TargetPath, IconLocation and IconIndex. Other parameters are ignored.

https://psappdeploytoolkit.com