Skip to content

Instantly share code, notes, and snippets.

@john-walks-slow
Created December 1, 2023 14:51
Show Gist options
  • Save john-walks-slow/71b889e1ca6241f447f68eb1e3677c10 to your computer and use it in GitHub Desktop.
Save john-walks-slow/71b889e1ca6241f447f68eb1e3677c10 to your computer and use it in GitHub Desktop.
Create an executable shortcut of ps1 script
# $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