PowerShell: Current Script Directory
Split-Path $MyInvocation.MyCommand.Path
Within a function
Split-Path $Script:MyInvocation.MyCommand.Path
$PSScriptRoot
if (!$PSScriptRoot) {$PSScriptRoot = Split-Path $Script:MyInvocation.MyCommand.Path}
Code Root
# $PWD.Path is the current directory (for when a function needs to run in or out of a script)
# $PSScriptRoot is the script directory (for in script only)
$CodeRoot = @($PSScriptRoot, $PWD.Path) | Where-Object { $_ } | Select-Object -First 1