-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreatePS_Shortcuts.ps1
More file actions
31 lines (24 loc) · 957 Bytes
/
CreatePS_Shortcuts.ps1
File metadata and controls
31 lines (24 loc) · 957 Bytes
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
[CmdletBinding()]
param (
[Parameter(ValueFromRemainingArguments=$true)]
$Path
)
'Paths'
$Path
$DesktopPath = [Environment]::GetFolderPath("Desktop")
$PSpath = "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe"
foreach($P in $Path){
#Create Shortcut and add Arguments
$name = (Get-Item $P).BaseName
$SCPath = $DesktopPath+"\"+$name+".lnk"
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($SCPath)
$Shortcut.Arguments = "-ExecutionPolicy Bypass -File {0} -WindowStyle Hidden" -f $P
$Shortcut.TargetPath = $PSpath
$Shortcut.Save()
#Make file Run as Admin
$bytes = [System.IO.File]::ReadAllBytes($SCPath)
#Set byte 21 (0x15) bit 6 (0x20) ON (Use –bor to set RunAsAdministrator option and –bxor to unset)
$bytes[0x15] = $bytes[0x15] -bor 0x20
[System.IO.File]::WriteAllBytes($SCPath, $bytes)
}