Skip to content

Instantly share code, notes, and snippets.

@markwragg
Created March 5, 2020 09:30
Show Gist options
  • Save markwragg/e7f92b93b05819fa64dbf34086ea87b4 to your computer and use it in GitHub Desktop.
Save markwragg/e7f92b93b05819fa64dbf34086ea87b4 to your computer and use it in GitHub Desktop.
PowerShell Profile snippet to save/return to last location on exit
$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
@varunswarup0
Copy link

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