我运行一个PowerShell脚本。如何获取我运行的这个脚本的目录路径?
该怎么做呢?
发布于 2013-07-04 11:52:30
PowerShell 3拥有$PSScriptRoot
automatic variable
包含运行脚本的目录。
在Windows PowerShell 2.0中,此变量仅在脚本模块(.psm1)中有效。从Windows PowerShell 3.0开始,它在所有脚本中都有效。
不要被糟糕的措辞所蒙蔽。PSScriptRoot
是当前文件的目录。
在PowerShell 2中,您可以自己计算$PSScriptRoot
的值:
# PowerShell v2
$PSScriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
https://stackoverflow.com/questions/17461237
复制相似问题