Skip to content

Instantly share code, notes, and snippets.

@Katzenwerfer
Last active February 15, 2023 18:27
Show Gist options
  • Save Katzenwerfer/440a40cee9b06703a3fbbc2742038a95 to your computer and use it in GitHub Desktop.
Save Katzenwerfer/440a40cee9b06703a3fbbc2742038a95 to your computer and use it in GitHub Desktop.
Initiate a PowerShell session that restarts on exit
function Restart-Session {
[Alias("ress")]
param ()
[System.Management.Automation.PathInfo]$pathInfo = Get-Location;
while ($true) {
powershell.exe -NoLogo -NoExit -Command "Set-Location $($pathInfo.Path)"
if ($LASTEXITCODE) {
Write-Host -Object "Infinite session stopped" -ForegroundColor Red
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment