From 3af684d74912efad113907a8f56a261a674d9f7b Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Mon, 15 Mar 2021 08:06:37 +0100 Subject: [PATCH] Add create-shortcut.ps1 --- Data/scripts.csv | 1 + README.md | 1 + Scripts/create-shortcut.ps1 | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100755 Scripts/create-shortcut.ps1 diff --git a/Data/scripts.csv b/Data/scripts.csv index 79b9eeb0..5d2b0370 100644 --- a/Data/scripts.csv +++ b/Data/scripts.csv @@ -20,6 +20,7 @@ close-thunderbird.ps1, closes Mozilla Thunderbird gracefully close-vlc.ps1, closes the VLC media player gracefully close-windows-terminal.ps1, closes Windows Terminal gracefully configure-git.ps1, sets up the Git user configuration +create-shortcut.ps1, creates a shortcut create-symlink.ps1, creates a symbolic link csv-to-text.ps1, converts the given CSV file into a text list daily-tasks.sh, execute PowerShell scripts automatically as daily tasks (Linux only) diff --git a/README.md b/README.md index 399ac83b..2c6583dd 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ Collection of PowerShell Scripts ----------------------------- * [check-symlinks.ps1](Scripts/check-symlinks.ps1) - checks every symlink in the given directory tree * [check-xml-file.ps1](Scripts/check-xml-file.ps1) - checks the given XML file for validity +* [create-shortcut.ps1](Scripts/create-shortcut.ps1) - creates a shortcut * [create-symlink.ps1](Scripts/create-symlink.ps1) - creates a symbolic link * [decrypt-file.ps1](Scripts/decrypt-file.ps1) - encrypts the given file * [encrypt-file.ps1](Scripts/encrypt-file.ps1) - encrypts the given file diff --git a/Scripts/create-shortcut.ps1 b/Scripts/create-shortcut.ps1 new file mode 100755 index 00000000..eb925c24 --- /dev/null +++ b/Scripts/create-shortcut.ps1 @@ -0,0 +1,35 @@ +#!/bin/powershell +<# +.SYNTAX ./create-shortcut.ps1 [] [] [] +.DESCRIPTION creates a new shortcut +.LINK https://github.com/fleschutz/PowerShell +.NOTES Author: Markus Fleschutz / License: CC0 +#> + +param($Shortcut = "", $Target = "", $Description) + +if ($Shortcut -eq "" ) { + $Shortcut = read-host "Enter filename of shortcut" +} +if ($Target -eq "" ) { + $Target = read-host "Enter path to target" +} +if ($Description -eq "" ) { + $Description = read-host "Enter description" +} + +try { + $sh = new-object -ComObject WScript.Shell + $shortcut = $sh.CreateShortcut("$Shortcut.lnk") + $shortcut.TargetPath = "$Target" + $shortcut.WindowStyle = "1" + $shortcut.IconLocation = "C:\Windows\System32\SHELL32.dll, 3" + $shortcut.Description = "$Description" + $shortcut.save() + + write-host -foregroundColor green "Done." + exit 0 +} catch { + write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + exit 1 +}