Your SlideShare is downloading. ×
PowerCLI in the Enterprise Breaking the Magicians Code   original
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

PowerCLI in the Enterprise Breaking the Magicians Code original


Published on

Published in: Technology

  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. @jonathanmedd
  • 2. PowerShell and PowerCLI Other programming languages are available……… …but the principles in this session can typically be applied to most of them.
  • 3. …move your code from the equivalent of this…. …to this………
  • 4. From Command to Script…..
  • 5. ….to Function Reasons for functions: Primary: Break up code to manageable, reusable chunks Also: 1. No cmdlet exists for a task 2. Existing cmdlet doesn’t behave like you want it to 3. String multiple cmdlets together
  • 6. Functions……. function Get-Something { Take some input Do something with it Produce some output } function Set-Something { Take some input Change the configuration of something }
  • 7. Function Recommendations 1) Name Your Functions Verb-Noun Get-VMHostLicense & Set-VMHostLicense Get-Verb | Sort Verb ….will give you a list of approved verbs
  • 8. Function Recommendations 2) Use Built-In Help
  • 9. Function Recommendations 3) Generalise everything! No hardcoded data in functions (or scripts)! Data should always come from an external source…CSV, XML, SQL database….etc
  • 10. Function Recommendations 4) Parameters
  • 11. Function Recommendations Pipeline Support ValueFromPipeline = $true and 5)
  • 12. Function Flexibility You need to be able to cater for pipeline support: Get-VMHost | Get-VMHostSomething as well as Get-VMHostSomething –VMHost ESXi01,ESXI02
  • 13. Function Templates Build up templates for Get-Something and SetSomething, then to create say GetVMHostiSCSIBinding, all you need is this:
  • 14. ….to Module A method to organise your functions into collections of functions  Easy to distribute via file copy / XCOPY  Easy to access all functions via:  Import-Module MyModule  Tip: Use a Module Manifest to make your module professional: New-ModuleManifest
  • 15. Modules  Typically will contain at least 2 files  *.psm1 - containing your functions  *.psd1 – the manifest  $env:PSModulePath contains the path Import- Module will look for modules ○ Typically this is your user profileDocumentsWindowsPowerShellModules and ○ C:Windowssystem32WindowsPowerShellv1.0Mo dules - use this one for deployment!
  • 16. Modules
  • 17. Modules: PSM1 Difficult to find individual functions  Hassle to maintain to keep them in a particular order 
  • 18. Nested Modules Break each module down into Nested Modules each containing a single function  Reference the Nested Modules in the *.psd1 
  • 19. Import-Module vSphereTools
  • 20. Module: Search  Search for string patterns dir * -Recurse | Select-String 'PSBoundParameters'
  • 21. Module: Search  Search for metadata Search-ModuleTag -Module vSphereTools -Tag ‘iscsi’
  • 22. Modules: Considerations  Module Dependencies – One module may requires functions from another module  Generic module with standard tools for other modules
  • 23. Flexibility  Now you have code broken down into Functions and Modules you can pick out various functions or entire modules to plug into:  Command line use  Scripts  Automation and Orchestration systems
  • 24. Backup / Source Control Internal File Share  Dropbox or other….   Git / Atlassian Stash  Free Atlassian SourceTree client for Windows and OSX. Works with all Git repositories (not just Stash), including GitHub
  • 25. Source Control – Version History
  • 26. Template Functions Will be available on my blog after this presentation ○ Get-Something ○ Set-Something ○ Get-VMSomething ○ Set-VMSomething ○ Get-VMHostSomething ○ Set-VMHostSomething
  • 27. Template Snippets And also these….Ctrl-J in PowerShell ISE
  • 28. Tweet Poll Results