如何获取PowerShell脚本的文件系统位置?
我有一个位于D:\temp的PowerShell脚本。 
当我运行这个脚本时,我想要列出文件的当前位置。 我该怎么做呢?
例如,这段代码将在DOSbatch file中完成; 我试图将其转换为PowerShell脚本…
 FOR /f "usebackq tokens=*" %%a IN ('%0') DO SET this_cmds_dir=%%~dpa CD /d "%this_cmds_dir%" 
	
PowerShell 3+
正在运行的脚本的path是:
 $PSCommandPath 
它的目录是:
 $PSScriptRoot 
PowerShell 2
正在运行的脚本的path是:
 $MyInvocation.MyCommand.Path 
它的目录是:
 $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent 
 罗马库兹明回答了这个问题。 我只是补充一点,如果你导入一个模块(通过Import-Module ),你可以访问模块内部的$PsScriptRoot自动variables – 它会告诉你模块的位置。