One-Liner: Dotting in vs. Running a Script

PowerShell scripts are a collection of functions and procedural code, right?  So often, I find myself wishing I had a function defined in a script in my interactive session, but the script doesn’t lend itself to being dotted into the environment.

if ($MyInvocation.invocationName -eq ‘.’) { break __outOfScript; }

Of course, this means you have to have all your functions defined above the if statement and all your procedural code below it, but functions should always be defined before procedural code, right? 🙂

Comments (0)