Gavin Barron, Solution Architect
March 22, 2014
ComCamp Auckland
PowerShell:
Automation for
Everyone
The only five commands you need
Rules for writing scripts
Demos
Intro
Wrap up
Our agenda
PowerShell: Automation for Everyone | 3
 SharePoint Server MVP
 Developer
 Skier
 http://gavinb.net
 @gavinbarron
 g...
PowerShell: Automation for Everyone | 4
Why Automate?
 Repeatability
 Reliability
 Save time?
 Eliminate boring manual...
PowerShell: Automation for Everyone | 5
Why PowerShell?
 Product specific cmdlets
 Able to run .NET code
 Hooks into WM...
The only five
commands you need
Your Awesome Presentation Title {Segoe UI 12 pt.}
Get-Command
Your Awesome Presentation Title {Segoe UI 12 pt.}
Get-Help
Your Awesome Presentation Title {Segoe UI 12 pt.}
Get-Member
Your Awesome Presentation Title {Segoe UI 12 pt.}
Where-Object
Your Awesome Presentation Title {Segoe UI 12 pt.}
ForEach-Object
Demos
Your Awesome Presentation Title {Segoe UI 12 pt.}
Find the command
you need
Your Awesome Presentation Title {Segoe UI 12 pt.}
Simple Pipeline Use
PowerShell: Automation for Everyone | 15
File renaming in .bat
@echo off
for /f "delims=" %%a in ('dir /b *.txt') do call ...
Rules for writing
scripts
PowerShell: Automation for Everyone | 17
Consider error cases
 What should you do when it goes pear shaped?
 Default beh...
PowerShell: Automation for Everyone | 18
Consider your outputs
 Write-Host
 Write-Output
 Write-Progress
 Add-Content
...
PowerShell: Automation for Everyone | 19
Have style!
 Use a coding convention
 Naming
 Casing
 Bracing
 Avoid aliases...
PowerShell: Automation for Everyone | 20
Leverage functions for re-use
 Small tasks
 Compose a script from functions
 F...
PowerShell: Automation for Everyone | 21
Use configuration files
$file =[xml] (Get-ChildItem $constantsFilePath)
$root = "...
Your Awesome Presentation Title {Segoe UI 12 pt.}
Script Examples
Wrap up
Your Awesome Presentation Title {Segoe UI 12 pt.}
Start scripting, it’s easy!
PowerShell: Automation for Everyone | 25
Handy resources
 http://blogs.technet.com/b/heyscriptingguy
 http://gallery.tec...
Any questions?
Email: gavin.barron@intergen.co.nz
Blog: http://gavinb.net
Twitter: @gavinbarron
Thank you
PowerShell: Automation for Everyone
Upcoming SlideShare
Loading in...5
×

PowerShell: Automation for Everyone

380

Published on

Intergen's Solution Architect and Microsoft MVP Gavin Barron presented "PowerShell: Automation for everyone" during the MVP CompCamp 2014, a worldwide event ran during the weekend of 22-23 March 2014.

Gavin's blog: http://gavinb.net/

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
380
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "PowerShell: Automation for Everyone"

  1. 1. Gavin Barron, Solution Architect March 22, 2014 ComCamp Auckland PowerShell: Automation for Everyone
  2. 2. The only five commands you need Rules for writing scripts Demos Intro Wrap up Our agenda
  3. 3. PowerShell: Automation for Everyone | 3  SharePoint Server MVP  Developer  Skier  http://gavinb.net  @gavinbarron  gavin.barron@intergen.co.nz Gavin Barron Solution Architect Your presenter
  4. 4. PowerShell: Automation for Everyone | 4 Why Automate?  Repeatability  Reliability  Save time?  Eliminate boring manual tasks
  5. 5. PowerShell: Automation for Everyone | 5 Why PowerShell?  Product specific cmdlets  Able to run .NET code  Hooks into WMI/COM  Object pipeline  Readable scripts
  6. 6. The only five commands you need
  7. 7. Your Awesome Presentation Title {Segoe UI 12 pt.} Get-Command
  8. 8. Your Awesome Presentation Title {Segoe UI 12 pt.} Get-Help
  9. 9. Your Awesome Presentation Title {Segoe UI 12 pt.} Get-Member
  10. 10. Your Awesome Presentation Title {Segoe UI 12 pt.} Where-Object
  11. 11. Your Awesome Presentation Title {Segoe UI 12 pt.} ForEach-Object
  12. 12. Demos
  13. 13. Your Awesome Presentation Title {Segoe UI 12 pt.} Find the command you need
  14. 14. Your Awesome Presentation Title {Segoe UI 12 pt.} Simple Pipeline Use
  15. 15. PowerShell: Automation for Everyone | 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. 16. Rules for writing scripts
  17. 17. PowerShell: Automation for Everyone | 17 Consider error cases  What should you do when it goes pear shaped?  Default behaviour is Ignore and Continue  $ErrorActionPreference  -ErrorAction  try{} catch{}
  18. 18. PowerShell: Automation for Everyone | 18 Consider your outputs  Write-Host  Write-Output  Write-Progress  Add-Content  Out-File
  19. 19. PowerShell: Automation for Everyone | 19 Have style!  Use a coding convention  Naming  Casing  Bracing  Avoid aliases  Be Consistent!
  20. 20. PowerShell: Automation for Everyone | 20 Leverage functions for re-use  Small tasks  Compose a script from functions  Functions are highly reusable  Cmdlet Binding Attribute  Parameters Attribute  Default Values
  21. 21. PowerShell: Automation for Everyone | 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. 22. Your Awesome Presentation Title {Segoe UI 12 pt.} Script Examples
  23. 23. Wrap up
  24. 24. Your Awesome Presentation Title {Segoe UI 12 pt.} Start scripting, it’s easy!
  25. 25. PowerShell: Automation for Everyone | 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. 26. Any questions?
  27. 27. Email: gavin.barron@intergen.co.nz Blog: http://gavinb.net Twitter: @gavinbarron Thank you
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×