If you want something that works inside and outside ISE, you can use
$MyInvocation.InvocationName
Since the full path and. \ YourScript.ps1 can be returned, you can parse the name with:
[Regex]::Match( $MyInvocation.InvocationName, '[^\\]+\Z', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase -bor [System.Text.RegularExpressions.RegexOptions]::SingleLine ).Value
source share