1 / 28

PowerShell: Automation for Everyone

PowerShell: Automation for Everyone. ComCamp Auckland. Gavin Barron, Solution Architect March 22, 2014. Our agenda. Intro. The only five commands you need. Demos. Rules for writing scripts. Wrap up. Your presenter. Gavin Barron Solution Architect. SharePoint Server MVP Developer

silver
Download Presentation

PowerShell: Automation for Everyone

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PowerShell: Automation for Everyone • ComCampAuckland • Gavin Barron, Solution ArchitectMarch 22, 2014

  2. Our agenda Intro The only five commands you need Demos Rules for writing scripts Wrap up

  3. Your presenter Gavin Barron Solution Architect • SharePoint Server MVP • Developer • Skier • http://gavinb.net • @gavinbarron • gavin.barron@intergen.co.nz

  4. Why Automate? Repeatability Reliability Save time? Eliminate boring manual tasks

  5. Why PowerShell? Product specific cmdlets Able to run .NET code Hooks into WMI/COM Object pipeline Readable scripts

  6. The only five commands you need

  7. Get-Command

  8. Get-Help

  9. Get-Member

  10. Where-Object

  11. ForEach-Object

  12. Demos

  13. Find the command you need

  14. Simple Pipeline Use

  15. File renaming in .bat @echo off for /f "delims=" %%a in ('dir /b *.txt') do call :dot "%%a" pause goto :EOF :dot set "var=%~n1" set "var=%var:.=_%"   echo ren %1 "%var%%~x1"

  16. Rules for writing scripts

  17. Consider error cases What should you do when it goes pear shaped? Default behaviour is Ignore and Continue $ErrorActionPreference -ErrorAction try{} catch{}

  18. Consider your outputs Write-Host Write-Output Write-Progress Add-Content Out-File

  19. Have style! • Use a coding convention • Naming • Casing • Bracing • Avoid aliases • Be Consistent!

  20. Leverage functions for re-use Small tasks Compose a script from functions Functions are highly reusable CmdletBinding Attribute Parameters Attribute Default Values

  21. Use configuration files $file =[xml] (Get-ChildItem $constantsFilePath) $root = "setup-config" $ConstantsNodeList = $file.$root.Constants foreach($property in $ConstantsNodeList.Property) { $key= $property.Key $value=$property.Value $webApp.Properties.Add($key,$value) } $webApp.Update()

  22. Script Examples

  23. Wrap up

  24. Start scripting, it’s easy!

  25. Handy resources http://blogs.technet.com/b/heyscriptingguy http://gallery.technet.microsoft.com/scriptcenter http://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=ITCG http://ss64.com/ps/ http://ss64.com/ps/syntax.html

  26. Any questions?

  27. Thank you • Email: gavin.barron@intergen.co.nz • Blog: http://gavinb.net • Twitter: @gavinbarron

  28. THE END

More Related