when relevant content is
added and updated.
Just recently I’ve found my self repeatedly working through a location, location pattern.
cd C:\test\ .\hello.ps1 cd C:\Scripts\
The pattern consists of changing to another folder. Running some code and then changing back to the original folder – assuming you can remember it.
I then remembered the location cmdlets
PS> Get-Command *-Location | ft -a CommandType Name Version Source ----------- ---- ------- ------ Cmdlet Get-Location 126.96.36.199 Microsoft.PowerShell.Management Cmdlet Pop-Location 188.8.131.52 Microsoft.PowerShell.Management Cmdlet Push-Location 184.108.40.206 Microsoft.PowerShell.Management Cmdlet Set-Location 220.127.116.11 Microsoft.PowerShell.Management
The 2 useful ones in this working pattern are Push-Location and Pop-Location
Push-Location adds the current location to the location stack and moves you to a new location if you supply a path
Pop-Location pulls the topmost location from the location stack and moves you to that location
The pattern then becomes
PS> Get-Location Path ---- C:\Scripts PS> Push-Location -Path C:\test\ PS> Get-Location Path ---- C:\test PS> .\hello.ps1 Hello world! PS> Pop-Location PS> Get-Location Path ---- C:\Scripts
Saves all that remembering stuff