PowerShell 环境操作与扩展功能全解析
1. 获取当前位置
在 PowerShell 中,若要确定当前位置,可使用以下两种方法:
- 使用 Get-Location
命令 :
PS > Get-Location
Path
----
C:\temp
PS > $currentLocation = (Get-Location).Path
PS > $currentLocation
C:\temp
- 使用
$pwd
自动变量 :
PS > $pwd
Path
----
C:\temp
PS > $currentLocation = $pwd.Path
PS > $currentLocation
C:\temp
需要注意的是,PowerShell 的“当前位置”概念有时与 PowerShell.exe
进程的“当前目录”不同。例如:
PS > Get-Location
Path
----
C:\temp
PS > Get-Process | Export-CliXml processes.xml
PS > $reader = N