Skip to content

Instantly share code, notes, and snippets.

@Ultraporing
Last active December 3, 2024 02:29
Show Gist options
  • Save Ultraporing/914655685252e1d7320f308902369771 to your computer and use it in GitHub Desktop.
Save Ultraporing/914655685252e1d7320f308902369771 to your computer and use it in GitHub Desktop.
Run Powershell Script in the same file with doubleclick Snippet. $ScriptHome is set as replacement for $PSScriptRoot since its unset. Put this snippet in the beginning of your .cmd file. Thanks to "kapitanrum" and "Tydaeus" on stackoverflow for the awesome snippet and explanation.
<# : batch script
@echo off
setlocal
cd %~dp0
start pwsh -executionpolicy remotesigned -NoExit -Command "Invoke-Expression $($ScriptHome = '%~dp0'; [System.IO.File]::ReadAllText('%~dpf0'))"
endlocal
goto:eof
#>
# here write your powershell commands...
# optionally set the window title
$host.ui.RawUI.WindowTitle = "My Powershell Script"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment