• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
PowerShell 8tips
 

PowerShell 8tips

on

  • 763 views

 

Statistics

Views

Total Views
763
Views on SlideShare
763
Embed Views
0

Actions

Likes
0
Downloads
22
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • MGB 2003 © 2003 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

PowerShell 8tips PowerShell 8tips Presentation Transcript

  • Windows PowerShell: Eight Tips and Tricks to Make You a Guru Don Jones Senior Partner & Principal Technologist Concentrated Technology, LLC
  • This slide deck was used in one of our many conference presentations. We hope you enjoy it, and invite you to use it within your own organization however you like. For more information on our company, including information on private classes and upcoming conference appearances, please visit our Web site, www.ConcentratedTech.com . For links to newly-posted decks, follow us on Twitter: @concentrateddon or @concentratdgreg This work is copyright ©Concentrated Technology, LLC
  • CAUTION: DEMOS AHEAD
    • This is a demonstration-intensive session (very few slides)
    • I will capture a shell transcript and save all of my scripts
    • You can download these (in a week or so) from ConcentratedTech.com (there ’s a “Conference Materials” link in the menu)
    • Don Jones • ConcentratedTech.com
  • 1: Remote Control
    • Uses WinRM / WS-MAN
    • Enable-PSRemoting (or GPO)
    • 1:1 – Enter-PSSession
    • 1:n – Invoke-Command
    • Persistent Connection – New-PSSession
    • Implicit – Import-PSSession
    • Don Jones • ConcentratedTech.com
  • 2A: Parameter Binding ByValue • Don Jones • ConcentratedTech.com Stop-Service Get-Service -inputObject -Name ServiceController
  • 2B: Parameter Binding ByPropertyName • Don Jones • ConcentratedTech.com Get-Process Get-ADComputer -computerName -id -name Computer Object Name cn osversion
  • 3: Splatting
    • Assemble parameters into a dictionary
    • $p = @{ 'name'='svchost'; 'computername'='server-r2 ’ }
    • Splat the dictionary
    • Ps @p
    • Don Jones • ConcentratedTech.com
  • 4: Tracing Commands
    • See exactly how parameter binding is working…
    • trace-command -name parameterbinding -pshost -exp { ps @p }
    • Don Jones • ConcentratedTech.com
  • 5: Suppressing Errors
    • Use –EA or –ErrorAction
    • Do not set $ErrorActionPreference globally or in a script
    • -EA SilentlyContinue – suppress
    • -EA Stop – catch using a Try…Catch block
    • Use –EV to capture the error into a variable for logging or analysis
    • Don Jones • ConcentratedTech.com
  • 6: Making a Tool
    • Move command into a function
    • Parameterize hardcoded stuff that might change each time
    • Save the file in a .psm1 file in… …/[My ]Documents/WindowsPowerShell/Modules/ module-name / module-name. psm1
    • Load using Import-Module modulename
    • Don Jones • ConcentratedTech.com
  • 7: Puncutation Puzzle
    • $_ = placeholder; only in designated areas
    • [int] = object type
    • $a[0] = array index
    • {get-process} = script block
    • “ string” and ‘string’
    • (order (of) execution)
    • @(array,of,items)
    • @{key=value;key2=value2} hashtables
    • $variable
    • % alias to “ForEach-Object”
    • Don Jones • ConcentratedTech.com
  • 8: Comment-Based Help
    • Create standard-formatted help… without doing any formatting
    • Help about_comment*
    • Add to the top of scripts to document the script; to a function to doc the function
    • Don Jones • ConcentratedTech.com
  • BONUS: GUI-Based Apps
    • PrimalForms / Visual PowerShell
    • www.primaltools.com
    • Create GUI, add code to events
    • Let ’s see!
    • Don Jones • ConcentratedTech.com
  • Final Notes…
    • Please be sure to submit a session evaluation form!
    • Download slides & materials from www.ConcentratedTech.com within one week!
    • Blog, URLs, and other information is also available at www.ConcentratedTech.com for your reference
    • Thank you very much!
    • Don Jones • ConcentratedTech.com
  • This slide deck was used in one of our many conference presentations. We hope you enjoy it, and invite you to use it within your own organization however you like. For more information on our company, including information on private classes and upcoming conference appearances, please visit our Web site, www.ConcentratedTech.com . For links to newly-posted decks, follow us on Twitter: @concentrateddon or @concentratdgreg This work is copyright ©Concentrated Technology, LLC