-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shortcut.ps1
50 lines (36 loc) · 1.25 KB
/
Shortcut.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
############################## GLOBALS ##############################
$global:debug = 0
$global:display = 'Normal'
$global:title = 'Shortcut'
$global:args = $args
############################## VARIABLES ##############################
$destinationFolder = [Environment]::GetFolderPath('Desktop')
############################## MAIN CODE ##############################
function main {
if ($global:debug) { $global:args; '' }
if ($global:args.count -eq 0) {
$global:args = @($PSCommandPath)
}
foreach ($arg in $global:args) {
if (Test-Path $arg -PathType Leaf) {
$destinationFile = "$destinationFolder\" + (Get-Item $arg).Basename + '.lnk'
if ($global:debug) { $destinationFile }
ps1Shortcut "$arg" "$destinationFile"
}
}
if ($global:debug) { ''; pause }
exit
}
############################## FUNCTIONS ##############################
function ps1Shortcut {
param (
[Parameter(Mandatory)] [string] $Source,
[Parameter(Mandatory)] [string] $Destination
)
$Shortcut = (New-Object -ComObject WScript.Shell).CreateShortcut($Destination)
$Shortcut.TargetPath = 'powershell.exe'
$Shortcut.Arguments = "-ExecutionPolicy Bypass -File `"${Source}`""
$Shortcut.Save()
}
############################## RUN MAIN CODE ##############################
main