Skip to content

Instantly share code, notes, and snippets.

@bindreams
Last active January 17, 2021 20:52
Show Gist options
  • Save bindreams/f8e2d631841023ac15233eb7375a39f8 to your computer and use it in GitHub Desktop.
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).
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