mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-08-09 05:04:39 +02:00
Add create-shortcut.ps1
This commit is contained in:
35
Scripts/create-shortcut.ps1
Executable file
35
Scripts/create-shortcut.ps1
Executable 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
|
||||
}
|
Reference in New Issue
Block a user