返回列表 发帖

[技术讨论] PowerShell获取当前目录路径

  1. Get-Location
复制代码
  1. Resolve-Path '.'
复制代码
  1. $ExecutionContext.SessionState.Path.CurrentFileSystemLocation
复制代码
环境所限,需要使用 PowerShell 2.0 版本。

本帖最后由 qazplm 于 2017-8-1 11:53 编辑
  1. (gi .).FullName
复制代码
  1. ($pwd).Path
复制代码
[Environment]::CurrentDirectory
[IO.Directory]::GetCurrentDirectory()
(New-Object -Com Scripting.FileSystemObject).GetFolder('.').Path
(New-Object -Com WScript.Shell).CurrentDirectory
1

评分人数

    • PS2.0: 感谢分享技术 + 1

TOP

回复 2# qazplm


感谢分享。测试了一下,前面2种方法成功,后面4种方法无法获取到希望的内容。

PS C:\Users\hello> cd C:\Test\
PS C:\Test> (gi .).FullName
C:\Test
PS C:\Test> ($pwd).Path
C:\Test
PS C:\Test> [Environment]::CurrentDirectory
C:\Users\hello
PS C:\Test> [IO.Directory]::GetCurrentDirectory()
C:\Users\hello
PS C:\Test> (New-Object -Com Scripting.FileSystemObject).GetFolder('.').Path
C:\Users\hello
PS C:\Test> (New-Object -Com WScript.Shell).CurrentDirectory
C:\Users\hello
环境所限,需要使用 PowerShell 2.0 版本。

TOP

返回列表