Shane O’Neill takes us through using Pester to test self-contained scripts:
Where things differ…
…could be when you try to accommodate different people and create a .ps1 file that both defines and calls a function. Self Contained scripts, if you would call them that.
Normally the reason that I’ve heard from this is you’re trying to help a non-technical minded person and they just want a file that they can open, hit “run”, and everything is done for them.
Have you ever tried to Pester test those files though? It’s not recommended, especially if your function removes or modifies objects.
Click through for a solution and read Shane’s update as well for a scenario where it doesn’t quite work as hoped.