Contact

Subscribe via Email

Subscribe via RSS/JSON

Categories

Recent Posts

Creative Commons Attribution 4.0 International License
© Rakhesh Sasidharan

Elsewhere

Find out if a script was dot-sourced or not

All PowerShell scripts have a default variable called $myinvocation.

Here’s the variable for a script I run directly:

And here’s the variable for a script I dot-source:

So if you want to check whether a script was dot-source or not check $myinvocation.InvocationName. If dot-sourced that would be a dot.

Find out if a script was dot-sourced or not by rakhesh is licensed under a Creative Commons Attribution 4.0 International License.