I work with SharePoint, and I work with PowerShell.
PowerShell scripts can easily become messy and unstructured, hard to troubleshoot.
The same concepts as "regular" programming apply: helper methods/functions, encapsulation, abstraction, etc.
But the main purpose of PowerShell is still, to automate things that otherwise would take loooooong time to do manually.
With time, I came up with a starter script for every usage, generic enough to allow me to start doing specific stuff right away, while taking advantage of nice snippets of code.
I'm not trying to solve any outstanding issues or represent any best practices, just sharing what is for me a life saver, due to the following:
- Ever wanted to be able to click "run" (double-click) and don't care if you bump into permissions issues, or remember to "run as administrator"?
- If the script crashes, you know exactly why, when and where, and you can also ensure objects are still disposed
- You will be sure that your working path is the same as the path the script itself is located
- Easily enabled logging/output capabilities
- Clear distinction between reusable code and parameter calls
Here it is, for the whole world to see.
Have any interesting PowerShell snippets? Feel free to share!