Laerte Junior has an article on writing re-usable Powershell scripts:
There are the rules that I use in my day-to-day work in PowerShell. They’ve worked well for me over the years, but I’m not saying that they are carved in stone.
-
Learn the languageYou need to treat PowerShell as a serious .NET language. Like C#, F# or VB, it is impossible to know what the language can do, such as its features or commands without understanding the language and its paradigms? You can cut and splice other people’s scripts but you must have a good feel for the way that the language works before you can proceed any further
-
Use The HelpFor PowerShell, the help system is the first thing you must reach for: it must be your best friend. The designers of the language intended it to be well-used.
-
Use the PowerShell CommunityThe PowerShell community is unique, because it has people who have come from a wide range of IT backgrounds. They bring their experience and wisdom with them. They will know more than you. The combination of skills multiplies the speed at which the language develops. Read their posts, download their script and learn from them.
-
Keep It Simple
-
Do not use Aliases, except for deliberate obfuscation.
-
Write with considerationDo not try to cram all your scripted process into one line. In the Shared and Corporate environment other people will maintain your code and will not necessarily have the same PowerShell knowledge as you. Be kind in your code.
After reading his article, check out Carlos Perez, et al’s Powershell Best Practices and Style Guide.