Created
December 1, 2023 14:51
-
-
Save john-walks-slow/71b889e1ca6241f447f68eb1e3677c10 to your computer and use it in GitHub Desktop.
Create an executable shortcut of ps1 script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# $ScriptPath: The path to the ps1 script. It could be either relative or absolute. | |
# A shortcut will be created in the working directory, named after the ps1 script | |
param ( [string]$ScriptPath ) | |
if ("" -ne $ScriptPath){ | |
$LnkPath = $ScriptPath.Split("\")[-1].Split(".")[0] + ".lnk" | |
$WshShell = New-Object -comObject WScript.Shell | |
$Shortcut = $WshShell.CreateShortcut($LnkPath) | |
$Shortcut.TargetPath = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" | |
$Shortcut.WorkingDirectory = $ScriptPath.Split("\")[0..($ScriptPath.Split("\").Length-2)] -join "\" | |
$Shortcut.Arguments = $ScriptPath | |
$Shortcut.Save() | |
} else { | |
Write-Host "Please provide script path" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment