20
Good PowerShell EXPAND YOUR POWERSHELL SKILLZ BY KIERAN JACOBSEN

Advanced PowerShell Automation

Embed Size (px)

DESCRIPTION

CMDLets, scripts, functions, methods and modules all make PowerShell sound very complicated however with some simple guidelines you too can become a PowerShell automation Pro!

Citation preview

  • 1. Good PowerShell EXPAND YOUR POWERSHELL SKILLZ BY KIERAN JACOBSEN
  • 2. 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
  • 3. 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
  • 4. 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
  • 5. 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
  • 6. Naming Conventions Functions and Cmdlets - Microsoft verbs Vs Defining your down Singular Nouns Modules Scripts Variables Parameters Case
  • 7. Comment Based Help Provides detailed help information on our own CMDLets Descriptions Examples Additional Information Links/References get-help about_comment_based_help
  • 8. Comments When and where is appropriate Variable declarations Complex IF/For/While/Until conditions Pipelining Input validation Error handling Anything complex Dont over do comments for simple/obvious lines of code.
  • 9. Handling Errors When to catch errors When to throw errors When to write-error Error Messages Exit codes
  • 10. Bring on the demos!
  • 11. Demo: Get a web page
  • 12. Demo: Reusable Get- WebPage
  • 13. Demo: Getting a file
  • 14. Demo: Reusable get-webfile
  • 15. Demo: Posting Data to a page in a reusable way
  • 16. Demo: A tour of a Web Functions module
  • 17. 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 Email Ability to provide high, normal and low priority notifications Ability to include a URL Alternatives are out there
  • 18. Demo: PushOver Notifications
  • 19. Demo: SysInternals Script
  • 20. Questions? Website: http://aperturescience.su Twitter: @kjacobsen Email [email protected] GitHub Projects WebFunctions: http://bit.ly/WebFunctions PushOverPS: http://bit.ly/PSPushOver