
PowerShellで現在のロケーションを変更するには、Set-Locationを使用しますが、Push-Locationを使うと変更先へのロケーションの移動とともに、移動先のロケーションをスタックに格納することができます。そして、Pop-Locationを使うことによりスタックに積まれたロケーションに順次移動することができます。

この例では、C:\workフォルダ配下に「image1」「image2」「image3」というフォルダがあるとします。
構文
Push-Location [変更先のロケーション]
PS C:\work> Push-Location C:\work\image1 PS C:\work\image1> Push-Location C:\work\image2 PS C:\work\image2> Push-Location C:\work\image3 PS C:\work\image3>

このようにスタックにロケーションが積まれるイメージです。
構文
Pop-Location
PS C:\work\image3> Pop-Location PS C:\work\image2> Pop-Location PS C:\work\image1> Pop-Location PS C:\work>

スタックから取り出すときは、最後に積まれたものから取り出します。
イメージ的にはこんな感じです。
スポンサーリンク