Octopus.Script exported 2015-12-23 by bobjwalker belongs to ‘Windows’ category.
Creates or updates a Windows shortcut to point to a target file.
Parameters
When steps based on the template are included in a project’s deployment process, the parameters below can be set.
Target file the shortcut will reference
TargetFilePath
This should be set to the file that the shortcut will link to.
Choose a destination for the shortcut or a Custom path.
ShortcutDestination = PublicDesktop
The path the shortcut will be put in if Custom path is chosen
ShortcutPath
This path is only used if Custom is set as destination for the shortcut. This should include a path that the shortcut should live in. If the path does not exist, it will be created.
The name of the shortcut
ShortcutName
This should be the name of the shortcut.
Script body
Steps based on this template will execute the following PowerShell script.
$destination = $OctopusParameters['ShortcutDestination']
$targetFilePath = $OctopusParameters['TargetFilePath']
$shortcutName = $OctopusParameters['Shortcutname']
#Use Custom or predefined path
$shortcutDestination =
if($destination -eq "PublicDesktop") { "$env:PUBLIC\Desktop" }
elseif($destination -eq "Custom") { $OctopusParameters['ShortcutPath'] }
else {Write-Error "Shortcut destination is not set"}
#Create shortcut filename
$shortcut = "$shortcutDestination\$shortcutName.lnk"
Write-Output "Shortcut: $shortcut"
Write-Output "Target: $targetFilePath"
if(!(Test-Path $destination)){
New-Item -ItemType Directory -Path $destination
}
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$shortcut")
$Shortcut.TargetPath = $targetFilePath
$Shortcut.Save()
Provided under the Apache License version 2.0.
To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.
{
"Id": "95ed2a99-f92a-482e-a625-bbd1fb7c24bc",
"Name": "Windows - Create Shortcut",
"Description": "Creates or updates a Windows shortcut to point to a target file.",
"Version": 7,
"ExportedAt": "2015-12-23T09:41:47.577+00:00",
"ActionType": "Octopus.Script",
"Author": "bobjwalker",
"Parameters": [
{
"Name": "TargetFilePath",
"Label": "Target file the shortcut will reference",
"HelpText": "This should be set to the file that the shortcut will link to.",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "ShortcutDestination",
"Label": "Choose a destination for the shortcut or a Custom path.",
"HelpText": "",
"DefaultValue": "PublicDesktop",
"DisplaySettings": {
"Octopus.ControlType": "Select",
"Octopus.SelectOptions": "PublicDesktop|Desktop (All Users)\nCustom|Custom"
}
},
{
"Name": "ShortcutPath",
"Label": "The path the shortcut will be put in if Custom path is chosen",
"HelpText": "This path is only used if Custom is set as destination for the shortcut. This should include a path that the shortcut should live in. If the path does not exist, it will be created.",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "ShortcutName",
"Label": "The name of the shortcut",
"HelpText": "This should be the name of the shortcut.",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
}
],
"Properties": {
"Octopus.Action.Script.ScriptBody": "$destination = $OctopusParameters['ShortcutDestination']\n$targetFilePath = $OctopusParameters['TargetFilePath']\n$shortcutName = $OctopusParameters['Shortcutname']\n\n#Use Custom or predefined path\n$shortcutDestination = \n if($destination -eq \"PublicDesktop\") { \"$env:PUBLIC\\Desktop\" }\n elseif($destination -eq \"Custom\") { $OctopusParameters['ShortcutPath'] }\n else {Write-Error \"Shortcut destination is not set\"}\n\n\n#Create shortcut filename\n$shortcut = \"$shortcutDestination\\$shortcutName.lnk\"\n\nWrite-Output \"Shortcut: $shortcut\"\nWrite-Output \"Target: $targetFilePath\"\n\nif(!(Test-Path $destination)){\n New-Item -ItemType Directory -Path $destination\n}\n\n$WshShell = New-Object -comObject WScript.Shell\n$Shortcut = $WshShell.CreateShortcut(\"$shortcut\")\n$Shortcut.TargetPath = $targetFilePath\n$Shortcut.Save()",
"Octopus.Action.Script.Syntax": "PowerShell"
},
"Category": "Windows",
"HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/windows-create-shortcut.json",
"Website": "/step-templates/95ed2a99-f92a-482e-a625-bbd1fb7c24bc",
"Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////Da3qSsLvhtb0wur6O7zuWcfxldv2aMzyK7ftpOD3s+X48Pr+0fD7d9HzHLLr4fX8xD/OcwAAAaNJREFUeNrs3cFygjAUQFECWott1f//2sJoW6kIKEzNs+euXOmcmSSGDa8oJEmSJEmSJGmsj1W1K9cpsGD1Vr2WdToVEPC+2lYvZfpVrEW0qZpF1F+MRdRugzoNlvkiarfBPk0pT8GhWUSX2yASpDlLr2+DEJBmEY1ug6whx7N0n2b30G1QlmmxHsRYp6X76yvF9vg5RYQczq8UVURI35UiFmTgShED0p6lI1eKzCHTrxS5Qk6PZ9PLDtJ9PIsJmXWlyAky6/dAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQMJCyjltF/iO3gpJUpD8s4OAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgID8T8itwwKyhbTdMr4ha8hXUwZqhICcOgyNOIkE+V5wo4MSgr1u/fp7poO+AL8K/gL8yw0UeyRB34m9iQ/pVD8L5JYTO3NI58R+AsiEEzsW5OfE3sUe/zRwYkeGnG2g2CPS7rhjF4GKP0ZwyoldxK37kFqEL/7wU0mSJEmSJOmJ+xRgAHxZTCXGdZkfAAAAAElFTkSuQmCC",
"$Meta": {
"Type": "ActionTemplate"
}
}
Page updated on Wednesday, December 23, 2015