Created
March 5, 2020 09:30
-
-
Save markwragg/e7f92b93b05819fa64dbf34086ea87b4 to your computer and use it in GitHub Desktop.
PowerShell Profile snippet to save/return to last location 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
$LastLocationFile = Join-Path $env:USERPROFILE 'lastlocation.txt' | |
If (Test-Path $LastLocationFile) { | |
Import-Clixml $LastLocationFile | Set-Location | |
} | |
Else { | |
Set-Location $env:USERPROFILE | |
} | |
Register-EngineEvent PowerShell.Exiting -Action { | |
Get-Location | Export-Clixml $LastLocationFile -Force | |
} | Out-Null |
It’s worth noting it only works if you end your PowerShell session by typing “exit” is that what you were doing?
Should have read the code more carefully 😅, Thanks a lot 😉.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, I tried this by removing everything from profile.ps1 and adding this snippet only.
It didn't work. 😭
Can you please upload your whole profile.ps1?
Thanks.