Use the built-in variable $MyInvocation (more specifically $MyInvocation.ScriptName). It's not exact because the value changes each time a function or script is called. You'd have to call it fairly early in the script, or you may have to go through all of the available scopes (which PowerShell keeps track of) to get to the top scope and then read it. Information in chapter 9 of Bruce Payette's book "Windows PowerShell in Action" as well as in Microsoft's documentation.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.