In batch, %~dpn0
returns the Drive, Path and Name of the currently executing script.
To do the same in a PowerShell script you can use $MyInvocation.MyCommand.Definition
.
eg:
$scriptPathAndName = $MyInvocation.MyCommand.Definition
write-host $scriptPathAndName
To get just the path to the script you could use:
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
write-host $scriptPath
(Note: in Powershell v3+ you can get the script's path (without the name) by referencing the predefined variable $PSScriptRoot
)
To get just the name of the script:
$scriptName = split-path -leaf $MyInvocation.MyCommand.Definition
write-host $scriptName
More info on Split-Path's options: https://technet.microsoft.com/en-us/library/hh849809.aspx