#PowerShell 的 Get-Location 命令
Get-Location [-PSProvider <String[]>] [-PSDrive <String[]>]
Get-Location [-Stack] [-StackName <String[]>]
功能
获取当前 PowerShell 工作位置。默认返回 PathInfo 对象,使用 .Path 可以取得路径字符串。位置也可以属于注册表等 PowerShell 提供程序。
类型
Cmdlet,属于 Microsoft.PowerShell.Management。
参数
-PSProvider查看指定提供程序的工作位置。也可以用-PSDrive查看指定 PowerShell 驱动器的位置。-Stack查看当前的路径堆栈。-StackName可以指定要查看的堆栈。
#示例
读取当前路径
(Get-Location).Path
/home/user/demo
示例输出随所在目录和平台变化。返回值也可以通过自动变量 $PWD 取得。