Last active
February 15, 2023 18:27
-
-
Save Katzenwerfer/440a40cee9b06703a3fbbc2742038a95 to your computer and use it in GitHub Desktop.
Initiate a PowerShell session that restarts on exit
This file contains hidden or 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
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