2021-04-21 19:53:52 +02:00
|
|
|
|
<#
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.SYNOPSIS
|
|
|
|
|
create-shortcut.ps1 [<shortcut>] [<target>] [<description>]
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
Creates a new shortcut file
|
|
|
|
|
.EXAMPLE
|
|
|
|
|
PS> .\create-shortcut.ps1 C:\Temp\HDD C:\
|
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz / License: CC0
|
2021-03-15 08:06:37 +01:00
|
|
|
|
#>
|
|
|
|
|
|
2021-07-15 15:51:22 +02:00
|
|
|
|
param([string]$Shortcut = "", [string]$Target = "", [string]$Description)
|
2021-03-15 08:06:37 +01:00
|
|
|
|
|
|
|
|
|
try {
|
2021-07-15 15:51:22 +02:00
|
|
|
|
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" }
|
|
|
|
|
|
2021-03-15 08:06:37 +01:00
|
|
|
|
$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()
|
|
|
|
|
|
2021-04-16 20:01:38 +02:00
|
|
|
|
write-host -foregroundColor green "✔️ shortcut $Shortcut created."
|
2021-03-15 08:06:37 +01:00
|
|
|
|
exit 0
|
|
|
|
|
} catch {
|
2021-05-02 21:30:48 +02:00
|
|
|
|
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
2021-03-15 08:06:37 +01:00
|
|
|
|
exit 1
|
|
|
|
|
}
|