Good PowerShell EXPAND YOUR POWERSHELL SKILLZ BY KIERAN JACOBSEN
Q. What makes a good piece of PowerShell code? Answer: The style of our code, including: Function architecture Naming Conventions Comments Use of Pipeline Error handling
Style Guides/conventions Style guide or coding/programming conventions are a set of rules used when writing the source code for a computer program [WikiPedia] Date back to the 1970s Claims to increase readability of and understand-ability of source code, and this reduce the chances of programming errors. Claims to reduce software maintenance costs Software developers all work with guides/conventions We have server naming conventions, account naming conventions, why not scripting conventions? One of the hardest things for any group to develop, agree upon and to stick to
Script? Function? CMDLet? Module? Function:Named sections of code CMDLet:Advanced reusable functions Script: Complex problems solved with functions and CMDLets Module:Collections of functions and CMDLets Libraries Configuration Application Compiled Code Development and Distribution
Functions and CMDLets First “Think functions not scripts” “Make CMDLets not scripts” Design functions and CMDLets first, then build very simple scripts Functions should do just ONE thing
Naming Conventions Functions and Cmdlets - Microsoft verbs Vs Defining your down Singular Nouns Modules Scripts Variables Parameters Case
Comment Based Help Provides detailed help information on our own CMDLets Descriptions Examples Additional Information Links/References get-help about_comment_based_help
Comments When and where is appropriate Variable declarations Complex IF/For/While/Until conditions Pipelining Input validation Error handling Anything complex Don’t over do comments for simple/obvious lines of code.
Handling Errors When to catch errors When to throw errors When to write-error Error Messages Exit codes
Bring on the demos!
Demo: Get a web page
Demo: Reusable Get- WebPage
Demo: Getting a file
Demo: Reusable get-webfile
Demo: Posting Data to a page in a reusable way
Demo: A tour of a “Web Functions” module
PushOver.net Provides push notification support for Android and iOS Available from App/Play Store Applications wishing to send notifications, simply post to API web interface or via Ability to provide high, normal and low priority notifications Ability to include a URL Alternatives are out there
Demo: PushOver Notifications
Demo: SysInternals Script
Demo: Chocolatey
Questions? Website: GitHub Projects WebFunctions: PushOverPS: