<t>PowerShell 3+<br/>
<br/>
# This is an automatic variable set to the current file's/module's directory<br/>
$PSScriptRoot<br/>
<br/>
```<br/><br/>
**PowerShell 2**<br/>
<br/>
Prior to PowerShell 3, there was not a better way than querying the<br/>MyInvocation.MyCommand.Definition` property for general scripts. I had the following line at the top of essentially every PowerShell script I had:<br/>
<br/>
<br/>
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition<br/>
<br/></t>