Last active
January 17, 2021 20:52
-
-
Save bindreams/f8e2d631841023ac15233eb7375a39f8 to your computer and use it in GitHub Desktop.
Script that launches a command in a new window. Prints exit code upon finish (-s to supress).
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
param( | |
[switch][Alias('s', 'silent')] $silentParameter, | |
[switch][Alias('e', 'elevate')] $elevateParameter | |
) | |
$pshost = if ($PSVersionTable.PSVersion.Major -le 5) {'powershell'} else {'pwsh'} | |
$elevate = if ($elevateParameter) {'-Verb RunAs'} else {''} | |
$finish = if ($silentParameter) {''} else {' | |
if ($lastexitcode -eq $null) { | |
echo """`nProcess finished."""; | |
read-host | |
} | |
else { | |
echo """`nProcess finished with code $lastexitcode"""; | |
read-host | |
} | |
'} | |
$expression = "start $pshost $elevate {-c | |
`$host.ui.RawUI.WindowTitle = '$args'; | |
$args; | |
$finish | |
}" | |
invoke-expression $expression |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment