Add create-shortcut.ps1

This commit is contained in:
Markus Fleschutz 2021-03-15 08:06:37 +01:00
parent 8b608c57a2
commit 3af684d749
3 changed files with 37 additions and 0 deletions

View File

@ -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)

1 Script Description
20 close-vlc.ps1 closes the VLC media player gracefully
21 close-windows-terminal.ps1 closes Windows Terminal gracefully
22 configure-git.ps1 sets up the Git user configuration
23 create-shortcut.ps1 creates a shortcut
24 create-symlink.ps1 creates a symbolic link
25 csv-to-text.ps1 converts the given CSV file into a text list
26 daily-tasks.sh execute PowerShell scripts automatically as daily tasks (Linux only)

View File

@ -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

35
Scripts/create-shortcut.ps1 Executable file
View File

@ -0,0 +1,35 @@
#!/bin/powershell
<#
.SYNTAX ./create-shortcut.ps1 [<shortcut>] [<target>] [<description>]
.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
}