约 876 字

约 4 分钟

#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 取得。

#推荐阅读

更新: 2026/11/27

作者: planc

创建: 2026/11/27