I am a beginner Powershell user. I am writing some script files (.ps1)
I would like to determine how my script was invoked:
Was is the "main" script or was it dot sourced from another file?
In python, I would use something like:
if __name__ == "__main__":
Is there something similar in PowerShell?
Update
After reading the answers, I am using the following at the end of my .ps1 file:
if ($MyInvocation.InvocationName -ne '.')
{
# do "main" stuff here
}
Any answers that include how this could fail are welcome.
It appears this is a duplicate question, I just didn't use the right search terms: Determine if PowerShell script has been dot-sourced