PowerShell 环境操作与功能扩展全解析
1. 获取当前位置
在 PowerShell 中,有时需要确定当前位置。可以使用 Get-Location 命令来实现,操作步骤如下:
1. 直接使用 Get-Location 命令查看当前位置:
PS > Get-Location
Path
----
C:\temp
- 若要将当前位置存储在变量中,可使用以下命令:
PS > $currentLocation = (Get-Location).Path
PS > $currentLocation
C:\temp
此外,PowerShell 还提供了 $pwd 自动变量来访问当前位置:
PS > $pwd
Path
----
C:\temp
PS > $currentLocation = $pwd.Path
PS > $currentLocation
C:\temp
需要注意的是,PowerShell 的“当前位置”概念有时与 PowerShell.exe 进程的“当前目录”不同。例如:
超级会员免费看
订阅专栏 解锁全文
1045

被折叠的 条评论
为什么被折叠?



