SlideShare a Scribd company logo
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

More Related Content

PPT
PowerShell crashcourse
PPTX
PowerShell crashcourse for sharepoint
PPTX
PowerShell crashcourse for Sharepoint admins
PPT
From VB Script to PowerShell
PPT
PS error handling and debugging
PPT
PS scripting and modularization
PPT
PowerShell Remoting
PPTX
PowerShell custom properties
PowerShell crashcourse
PowerShell crashcourse for sharepoint
PowerShell crashcourse for Sharepoint admins
From VB Script to PowerShell
PS error handling and debugging
PS scripting and modularization
PowerShell Remoting
PowerShell custom properties

What's hot (20)

PPT
Supporting SQLserver
PPT
PPT
Prepping software for w7 deployment
PPT
Top ESXi command line v2.0
PPTX
Virtualization auditing & security deck v1.0
PPT
Wsus sample scripts
PPT
Securely connecting to apps over the internet using rds
PPT
Rapidly deploying software
PPTX
PPT
Automating Active Directory mgmt in PowerShell
PPTX
Ideal Deployment In .NET World
PPTX
Pantheon basics
PPT
Crossover
PDF
Ako na vlastne WP temy
KEY
Features, Exportables & You
PPTX
Wsv315 Windows Power Shell For Beginners
PPTX
NMS Media Services Jobshet 1 to 5 Summary
PPTX
Wsv406 Advanced Automation Using Windows Power Shell2.0
PDF
UKLUG 2012 - XPages, Beyond the basics
PPT
XPages -Beyond the Basics
Supporting SQLserver
Prepping software for w7 deployment
Top ESXi command line v2.0
Virtualization auditing & security deck v1.0
Wsus sample scripts
Securely connecting to apps over the internet using rds
Rapidly deploying software
Automating Active Directory mgmt in PowerShell
Ideal Deployment In .NET World
Pantheon basics
Crossover
Ako na vlastne WP temy
Features, Exportables & You
Wsv315 Windows Power Shell For Beginners
NMS Media Services Jobshet 1 to 5 Summary
Wsv406 Advanced Automation Using Windows Power Shell2.0
UKLUG 2012 - XPages, Beyond the basics
XPages -Beyond the Basics
Ad

Viewers also liked (13)

KEY
PowerShell and the Future of Windows Automation
PPTX
Combining output from multiple sources
PPTX
Ive got a powershell secret
PPTX
Managing enterprise with PowerShell remoting
PPT
Ha & drs gotcha's
PPT
Free tools for win server administration
PPTX
VDI-in-a-Box: Microsoft Desktop Virtualization for Smaller Businesses and Uses
PPT
PowerShell Functions
PPTX
Implementing dr w. hyper v clustering
PPT
PowerShell v4 Desired State Configuration
PPT
Managing SQLserver
PPT
Automating ad with powershell
PDF
Advanced Tools & Scripting with PowerShell 3.0 Jump Start - Certificate
PowerShell and the Future of Windows Automation
Combining output from multiple sources
Ive got a powershell secret
Managing enterprise with PowerShell remoting
Ha & drs gotcha's
Free tools for win server administration
VDI-in-a-Box: Microsoft Desktop Virtualization for Smaller Businesses and Uses
PowerShell Functions
Implementing dr w. hyper v clustering
PowerShell v4 Desired State Configuration
Managing SQLserver
Automating ad with powershell
Advanced Tools & Scripting with PowerShell 3.0 Jump Start - Certificate
Ad

Similar to PowerShell 8tips (20)

PPTX
Admin SharePoint 2010 with PowerShell
PPTX
[Mas 500] Software Development Strategies
PDF
Under the Wire PowerShell workshop - BSides Augusta 2018
PDF
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
PPTX
O365 Developer Bootcamp NJ 2018 - Material
PPT
Where's the source, Luke? : How to find and debug the code behind Plone
PPTX
Holy PowerShell, BATman! - dogfood edition
PPTX
Meet Windows PowerShell
PPTX
Inventory your network and clients with PowerShell
PPT
Case study
PPTX
Admin share point with powershell
PDF
Lean Drupal Repositories with Composer and Drush
PDF
DomDisc and the Domino data api
PPTX
PowerShell - Be A Cool Blue Kid
PDF
Expanding XPages with Bootstrap Plugins for Ultimate Usability
PPTX
Build Your First SharePoint Framework Webpart
PDF
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
PPTX
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
PDF
IBM ConnectED 2015 - BP106 From XPages Hero To OSGi Guru: Taking The Scary Ou...
PDF
The "Holy Grail" of Dev/Ops
Admin SharePoint 2010 with PowerShell
[Mas 500] Software Development Strategies
Under the Wire PowerShell workshop - BSides Augusta 2018
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
O365 Developer Bootcamp NJ 2018 - Material
Where's the source, Luke? : How to find and debug the code behind Plone
Holy PowerShell, BATman! - dogfood edition
Meet Windows PowerShell
Inventory your network and clients with PowerShell
Case study
Admin share point with powershell
Lean Drupal Repositories with Composer and Drush
DomDisc and the Domino data api
PowerShell - Be A Cool Blue Kid
Expanding XPages with Bootstrap Plugins for Ultimate Usability
Build Your First SharePoint Framework Webpart
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
IBM ConnectED 2015 - BP106 From XPages Hero To OSGi Guru: Taking The Scary Ou...
The "Holy Grail" of Dev/Ops

More from Concentrated Technology (9)

PPTX
Wsus best practices
PPT
Virtualization today
PPTX
PowerShell crash course
PPTX
PowerShell and WMI
PPT
No-script PowerShell v2
PPTX
Managing SQLserver for the reluctant DBA
PPT
Iis implementation
PPT
Hyper v r2 deep dive
PPT
How to configure esx to pass an audit
Wsus best practices
Virtualization today
PowerShell crash course
PowerShell and WMI
No-script PowerShell v2
Managing SQLserver for the reluctant DBA
Iis implementation
Hyper v r2 deep dive
How to configure esx to pass an audit

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Encapsulation theory and applications.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
KodekX | Application Modernization Development
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Electronic commerce courselecture one. Pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
Teaching material agriculture food technology
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Network Security Unit 5.pdf for BCA BBA.
Chapter 3 Spatial Domain Image Processing.pdf
Empathic Computing: Creating Shared Understanding
Encapsulation theory and applications.pdf
Modernizing your data center with Dell and AMD
Review of recent advances in non-invasive hemoglobin estimation
KodekX | Application Modernization Development
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
MYSQL Presentation for SQL database connectivity
Electronic commerce courselecture one. Pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Teaching material agriculture food technology
CIFDAQ's Market Insight: SEC Turns Pro Crypto
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Spectral efficient network and resource selection model in 5G networks
20250228 LYD VKU AI Blended-Learning.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

PowerShell 8tips

  • 1. Windows PowerShell: Eight Tips and Tricks to Make You a Guru Don Jones Senior Partner & Principal Technologist Concentrated Technology, LLC
  • 2. 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
  • 3. 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
  • 4. 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
  • 5. 2A: Parameter Binding ByValue • Don Jones • ConcentratedTech.com Stop-Service Get-Service -inputObject -Name ServiceController
  • 6. 2B: Parameter Binding ByPropertyName • Don Jones • ConcentratedTech.com Get-Process Get-ADComputer -computerName -id -name Computer Object Name cn osversion
  • 7. 3: Splatting Assemble parameters into a dictionary $p = @{ 'name'='svchost'; 'computername'='server-r2 ’ } Splat the dictionary Ps @p • Don Jones • ConcentratedTech.com
  • 8. 4: Tracing Commands See exactly how parameter binding is working… trace-command -name parameterbinding -pshost -exp { ps @p } • Don Jones • ConcentratedTech.com
  • 9. 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
  • 10. 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
  • 11. 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
  • 12. 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
  • 13. BONUS: GUI-Based Apps PrimalForms / Visual PowerShell www.primaltools.com Create GUI, add code to events Let ’s see! • Don Jones • ConcentratedTech.com
  • 14. 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
  • 15. 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

Editor's Notes

  • #2: 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.