Powershell 包含 Pushd 和 Popd 的别名。
Get-Alias Pushd : pushd -> Push-Location
Get-Alias Popd : popd -> Pop-Location
您可以使用Get-Help Push-Location -Full -Online
命令获取该命令的最新帮助文档。
然后只需编写脚本并测试此行为即可。
#Sample.ps1 script
#Get current DIR
dir
#push location to some location and DIR there.
Push-Location C:\Scripts\
dir
#at this point, your console will still be in the Push-Location directory
#simply run the Pop-Location cmdlet to switch back.
cmd
运行批处理文件时,它们在同一实例中执行)。 当前目录是一个进程级别的概念,因此在一个进程中更改它对另一个进程没有影响。
可能最简单的方法是编写一个“cs.ps1”脚本(或函数),它将在PowerShell进程中运行。