Search notes:

PowerShell: The automatic variables $PSScriptRoot and $PSCommandPath

When evaluated within a script being executed, the automatic variable $psScriptRoot contains the absolute path of the directory where that script is located and $psCommandPath the absolute path of the script itself.
These variables evaluate to $null if they're not used within a script.
Because $PSScriptRoot evaluates to the module directory when used in a module script file (.psm1), it comes in handy to reference other resources that are related to a module.

See also

Determining the name and directory of a PowerShell script within the script itself.
Other automatic variables, especially $myInvocation.psScriptRoot, $myInvocation.psCommandPath, $myInvocation.mycommand.path and $myInvocation.myCommand.name.

Index