SlideShare a Scribd company logo
Scripting and Modularization in Windows PowerShell Don Jones ConcentratedTech.com Learn Windows PowerShell in 2 Days / Part 4
Welcome! This is one of four sessions designed to teach specific Windows PowerShell skills Don Jones Windows PowerShell MVP Award Recipient PowerShell Columnist for  Microsoft TechNet Magazine “ Decision Maker” Columnist for  Redmond Magazine Author,  Learn Windows PowerShell in a Month of Lunches Co-Author,  Windows PowerShell v2.0: TFM Creator of numerous self-paced PowerShell training videos for CBTNuggets.com.
Agenda Scripting language overview (and where to find the docs) Modularization: Going from a command to your very own cmdlet-like tool that can be easily distributed to other administrators If we have time, we’ll even touch on error handling and add that to the example!
Caution: Demos Ahead! Please note:  This session is built primarily around demonstrations, and answering your questions. You won’t see many slides. If you’re looking for additional written resources, there are lots to choose from (including many free ones) – the closing slide will list some key URLs Reference slides in this deck contain reminders for key help topics and commands
Bonus I’ll also post any scripts, as well as these slides. Download location will be listed at the end of this session. Don’t bother copying down commands – you’ll be able to download the whole session!
The Master Plan Let’s create a distributable module It will contain a command that retrieves inventory information from one or more computer We’ll start by describing the ways in which we want the command to operate, and then build it to match We’ll wrap with a discussion on modularization design principles
Scripting Constructs PowerShell isn’t a scripting language… but it contains a small one We’ll look at three key constructs; there are others, but they’re less-frequently used If…ElseIf…Else ForEach Do…While
Let’s Start Building We’ll start in the console with a single command… … and move into a script editor to build upon it. Script editors you should know about: PowerGUI (powergui.org)    free edition available PowerShell Plus (idera.com) PrimalScript (sapien.com) PowerSE (devfarms.com)    free
Reference: Key Help Files Help about_*  Complete list of these and other topics About_if, About_ForEach, About_Select, etc for specific help with constructs About_Functions_Advanced_* for help on “script cmdlets” (Advanced Functions) About_Comment_Based_Help About_Modules
Reference: Script Modules Think of a module name… like “Fred.” \Documents \WindowsPowerShell \Modules \Fred Fred.psm1
Reference: Manifest Modules If your script module depends upon other modules, create a manifest using  New-ModuleManifest Specify your module name as the root module Specify your dependencies as  nested modules Name the manifest  modulename .psd1 (e.g., fred.psd1) Now, Import-Module will load your module  and  the ones it depends upon (if they’re not already loaded)
Design Principles One function, one task: Get something (e.g., computer names from a DB) Do something (operate against a bunch of something) Deal with output (format, export, etc) Functions should rarely include internal filtering, sorting, etc – output objects and let PowerShell’s native cmdlets do that Scripts shouldn’t be 900 lines that do 50 things – break each task down into a discrete function, and then call the functions
PowerShell Proverbs Every time someone writes a PowerShell command that outputs text instead of objects, God kills a puppy. Harsh, but true.  Output objects.  There are a variety of syntaxes for doing so – I’ve used the one that most people find readable and concise.
Thank You! Please feel free to hit me up with any remaining questions between sessions Please submit a session evaluation!  These are an extremely important part of ensuring that the conference continues to provide you with the education you need! Resources and URLs on the next slide…
Remember! Slides, and scripts will be posted within a few days. You’re welcome to download whatever you like; please don’t re-post anything elsewhere on the Internet. For the download URL, see my Twitter feed: @concentrateddon Twitter.com/concentrateddon
More PowerShell Resources Web Sites ShellHub.com Bit.ly/DonJones YouTube.com/ ConcentratedDon ITPro. ConcentratedTech.com Thank you again for attending! Available Here!

More Related Content

What's hot (20)

PPTX
Software Design
mohamedsaad24
 
PPTX
Try harder or go home
jaredhaight
 
PPTX
Unit testing presentation
Arthur Freyman
 
PPT
Php mysql ppt
Karmatechnologies Pvt. Ltd.
 
PPT
Overview of PHP and MYSQL
Deblina Chowdhury
 
PPT
Control Structures In Php 2
Digital Insights - Digital Marketing Agency
 
PPT
Php Best Practices
Ansar Ahmed
 
PPT
PHP
sometech
 
PPT
PHP - Introduction to PHP Date and Time Functions
Vibrant Technologies & Computers
 
PPT
Php(report)
Yhannah
 
PPT
PHP complete reference with database concepts for beginners
Mohammed Mushtaq Ahmed
 
PPT
Php mysql
Shehrevar Davierwala
 
PPT
Php Presentation
Manish Bothra
 
PDF
Basic commands for powershell : Configuring Windows PowerShell and working wi...
Hitesh Mohapatra
 
PDF
Php a dynamic web scripting language
Elmer Concepcion Jr.
 
PPT
Scryent: Plone - Hone Your Test Fu
Jordan Baker
 
PPTX
Introduction to-php
AhmedAElHalimAhmed
 
PPTX
PHP slides
Farzad Wadia
 
PPTX
PHP FUNCTIONS
Zeeshan Ahmed
 
Software Design
mohamedsaad24
 
Try harder or go home
jaredhaight
 
Unit testing presentation
Arthur Freyman
 
Overview of PHP and MYSQL
Deblina Chowdhury
 
Control Structures In Php 2
Digital Insights - Digital Marketing Agency
 
Php Best Practices
Ansar Ahmed
 
PHP - Introduction to PHP Date and Time Functions
Vibrant Technologies & Computers
 
Php(report)
Yhannah
 
PHP complete reference with database concepts for beginners
Mohammed Mushtaq Ahmed
 
Php Presentation
Manish Bothra
 
Basic commands for powershell : Configuring Windows PowerShell and working wi...
Hitesh Mohapatra
 
Php a dynamic web scripting language
Elmer Concepcion Jr.
 
Scryent: Plone - Hone Your Test Fu
Jordan Baker
 
Introduction to-php
AhmedAElHalimAhmed
 
PHP slides
Farzad Wadia
 
PHP FUNCTIONS
Zeeshan Ahmed
 

Viewers also liked (20)

PPTX
10 PowerShell Mistakes, Trips and Traps
Jeffery Hicks
 
PPTX
Wsv315 Windows Power Shell For Beginners
jsnover1
 
PPTX
Wsv406 Advanced Automation Using Windows Power Shell2.0
jsnover1
 
PPTX
Everything you need to know about PowerShell
Shane Hoey
 
PPTX
Windows 2012 R2 Multi Server Management
Sharkrit JOBBO
 
PDF
VMUG - Mastering PowerShell to Call RESTful API Endpoints
Chris Wahl
 
PPTX
Introduction To Windows Power Shell
Microsoft TechNet
 
PPTX
PowerShell crashcourse for Sharepoint admins
Concentrated Technology
 
PPTX
Managing enterprise with PowerShell remoting
Concentrated Technology
 
PPT
Server Core2
Concentrated Technology
 
PPT
Free tools for win server administration
Concentrated Technology
 
PPTX
Combining output from multiple sources
Concentrated Technology
 
PPT
Managing SQLserver
Concentrated Technology
 
PPTX
Implementing dr w. hyper v clustering
Concentrated Technology
 
PPT
Automating ad with powershell
Concentrated Technology
 
PPTX
Introduction to powershell
Salaudeen Rajack
 
PPTX
Best free tools for w d a
Concentrated Technology
 
PPTX
PowerShell and WMI
Concentrated Technology
 
PPTX
PowerShell crashcourse for sharepoint
Concentrated Technology
 
PPT
Automating Active Directory mgmt in PowerShell
Concentrated Technology
 
10 PowerShell Mistakes, Trips and Traps
Jeffery Hicks
 
Wsv315 Windows Power Shell For Beginners
jsnover1
 
Wsv406 Advanced Automation Using Windows Power Shell2.0
jsnover1
 
Everything you need to know about PowerShell
Shane Hoey
 
Windows 2012 R2 Multi Server Management
Sharkrit JOBBO
 
VMUG - Mastering PowerShell to Call RESTful API Endpoints
Chris Wahl
 
Introduction To Windows Power Shell
Microsoft TechNet
 
PowerShell crashcourse for Sharepoint admins
Concentrated Technology
 
Managing enterprise with PowerShell remoting
Concentrated Technology
 
Free tools for win server administration
Concentrated Technology
 
Combining output from multiple sources
Concentrated Technology
 
Managing SQLserver
Concentrated Technology
 
Implementing dr w. hyper v clustering
Concentrated Technology
 
Automating ad with powershell
Concentrated Technology
 
Introduction to powershell
Salaudeen Rajack
 
Best free tools for w d a
Concentrated Technology
 
PowerShell and WMI
Concentrated Technology
 
PowerShell crashcourse for sharepoint
Concentrated Technology
 
Automating Active Directory mgmt in PowerShell
Concentrated Technology
 
Ad

Similar to PowerShell Scripting and Modularization (TechMentor Fall 2011) (20)

PPTX
Power shell training
David Brabant
 
PDF
Windows Powershell in Action 1st Edition Bruce G. Payette
zahithovor
 
PPT
PS scripting and modularization
Concentrated Technology
 
PPTX
Holy PowerShell, BATman! - dogfood edition
Dave Diehl
 
PPT
From VB Script to PowerShell
Concentrated Technology
 
PDF
Windows Powershell in Action 1st Edition Bruce G. Payette
moudenongui20
 
PDF
Powershell notes
Carlos Amorim
 
PDF
Windows Powershell in Action 1st Edition Bruce G. Payette
takabedembe
 
PPTX
PowerShell for Penetration Testers
Nikhil Mittal
 
PDF
Sql Server & PowerShell
Aaron Shilo
 
PPTX
In just one hour i will make you a power shell ninja
Jason Brown
 
PDF
PowerShell in Depth An administrator s guide Don Jones
lekwalakha3p
 
PPTX
PowerShell 101 - What is it and Why should YOU Care!
Thomas Lee
 
PDF
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
ClapperboardCinemaPV
 
PPT
PowerShell 8tips
Concentrated Technology
 
PDF
Powershell training material
Dr. Awase Khirni Syed
 
PPTX
Meet Windows PowerShell
Concentrated Technology
 
PDF
Practical PowerShell Programming for Professional People
Ben Ten (0xA)
 
PPTX
Introduction to PowerShell and getting started
Ravikanth Chaganti
 
PPTX
PowerShell-1
Saravanan G
 
Power shell training
David Brabant
 
Windows Powershell in Action 1st Edition Bruce G. Payette
zahithovor
 
PS scripting and modularization
Concentrated Technology
 
Holy PowerShell, BATman! - dogfood edition
Dave Diehl
 
From VB Script to PowerShell
Concentrated Technology
 
Windows Powershell in Action 1st Edition Bruce G. Payette
moudenongui20
 
Powershell notes
Carlos Amorim
 
Windows Powershell in Action 1st Edition Bruce G. Payette
takabedembe
 
PowerShell for Penetration Testers
Nikhil Mittal
 
Sql Server & PowerShell
Aaron Shilo
 
In just one hour i will make you a power shell ninja
Jason Brown
 
PowerShell in Depth An administrator s guide Don Jones
lekwalakha3p
 
PowerShell 101 - What is it and Why should YOU Care!
Thomas Lee
 
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
ClapperboardCinemaPV
 
PowerShell 8tips
Concentrated Technology
 
Powershell training material
Dr. Awase Khirni Syed
 
Meet Windows PowerShell
Concentrated Technology
 
Practical PowerShell Programming for Professional People
Ben Ten (0xA)
 
Introduction to PowerShell and getting started
Ravikanth Chaganti
 
PowerShell-1
Saravanan G
 
Ad

More from Concentrated Technology (19)

PPT
Wsus sample scripts
Concentrated Technology
 
PPTX
Wsus best practices
Concentrated Technology
 
PPT
Virtualization today
Concentrated Technology
 
PPTX
Virtualization auditing & security deck v1.0
Concentrated Technology
 
PPTX
Vdi in-a-box
Concentrated Technology
 
PPT
Top ESXi command line v2.0
Concentrated Technology
 
PPT
Supporting SQLserver
Concentrated Technology
 
PPT
Securely connecting to apps over the internet using rds
Concentrated Technology
 
PPT
Rapidly deploying software
Concentrated Technology
 
PPT
PS error handling and debugging
Concentrated Technology
 
PPT
Prepping software for w7 deployment
Concentrated Technology
 
PPT
PowerShell Remoting
Concentrated Technology
 
PPT
PowerShell crashcourse
Concentrated Technology
 
PPTX
PowerShell custom properties
Concentrated Technology
 
PPTX
PowerShell crash course
Concentrated Technology
 
PPTX
Managing SQLserver for the reluctant DBA
Concentrated Technology
 
PPTX
Inventory your network and clients with PowerShell
Concentrated Technology
 
PPT
Iis implementation
Concentrated Technology
 
PPT
Hyper v r2 deep dive
Concentrated Technology
 
Wsus sample scripts
Concentrated Technology
 
Wsus best practices
Concentrated Technology
 
Virtualization today
Concentrated Technology
 
Virtualization auditing & security deck v1.0
Concentrated Technology
 
Top ESXi command line v2.0
Concentrated Technology
 
Supporting SQLserver
Concentrated Technology
 
Securely connecting to apps over the internet using rds
Concentrated Technology
 
Rapidly deploying software
Concentrated Technology
 
PS error handling and debugging
Concentrated Technology
 
Prepping software for w7 deployment
Concentrated Technology
 
PowerShell Remoting
Concentrated Technology
 
PowerShell crashcourse
Concentrated Technology
 
PowerShell custom properties
Concentrated Technology
 
PowerShell crash course
Concentrated Technology
 
Managing SQLserver for the reluctant DBA
Concentrated Technology
 
Inventory your network and clients with PowerShell
Concentrated Technology
 
Iis implementation
Concentrated Technology
 
Hyper v r2 deep dive
Concentrated Technology
 

Recently uploaded (20)

PDF
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
PDF
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
PDF
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
PDF
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PDF
Quantum Threats Are Closer Than You Think – Act Now to Stay Secure
WSO2
 
PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PPTX
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
PDF
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PDF
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
PDF
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
PPTX
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PPTX
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PDF
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
Quantum Threats Are Closer Than You Think – Act Now to Stay Secure
WSO2
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 

PowerShell Scripting and Modularization (TechMentor Fall 2011)

  • 1. Scripting and Modularization in Windows PowerShell Don Jones ConcentratedTech.com Learn Windows PowerShell in 2 Days / Part 4
  • 2. Welcome! This is one of four sessions designed to teach specific Windows PowerShell skills Don Jones Windows PowerShell MVP Award Recipient PowerShell Columnist for Microsoft TechNet Magazine “ Decision Maker” Columnist for Redmond Magazine Author, Learn Windows PowerShell in a Month of Lunches Co-Author, Windows PowerShell v2.0: TFM Creator of numerous self-paced PowerShell training videos for CBTNuggets.com.
  • 3. Agenda Scripting language overview (and where to find the docs) Modularization: Going from a command to your very own cmdlet-like tool that can be easily distributed to other administrators If we have time, we’ll even touch on error handling and add that to the example!
  • 4. Caution: Demos Ahead! Please note: This session is built primarily around demonstrations, and answering your questions. You won’t see many slides. If you’re looking for additional written resources, there are lots to choose from (including many free ones) – the closing slide will list some key URLs Reference slides in this deck contain reminders for key help topics and commands
  • 5. Bonus I’ll also post any scripts, as well as these slides. Download location will be listed at the end of this session. Don’t bother copying down commands – you’ll be able to download the whole session!
  • 6. The Master Plan Let’s create a distributable module It will contain a command that retrieves inventory information from one or more computer We’ll start by describing the ways in which we want the command to operate, and then build it to match We’ll wrap with a discussion on modularization design principles
  • 7. Scripting Constructs PowerShell isn’t a scripting language… but it contains a small one We’ll look at three key constructs; there are others, but they’re less-frequently used If…ElseIf…Else ForEach Do…While
  • 8. Let’s Start Building We’ll start in the console with a single command… … and move into a script editor to build upon it. Script editors you should know about: PowerGUI (powergui.org)  free edition available PowerShell Plus (idera.com) PrimalScript (sapien.com) PowerSE (devfarms.com)  free
  • 9. Reference: Key Help Files Help about_* Complete list of these and other topics About_if, About_ForEach, About_Select, etc for specific help with constructs About_Functions_Advanced_* for help on “script cmdlets” (Advanced Functions) About_Comment_Based_Help About_Modules
  • 10. Reference: Script Modules Think of a module name… like “Fred.” \Documents \WindowsPowerShell \Modules \Fred Fred.psm1
  • 11. Reference: Manifest Modules If your script module depends upon other modules, create a manifest using New-ModuleManifest Specify your module name as the root module Specify your dependencies as nested modules Name the manifest modulename .psd1 (e.g., fred.psd1) Now, Import-Module will load your module and the ones it depends upon (if they’re not already loaded)
  • 12. Design Principles One function, one task: Get something (e.g., computer names from a DB) Do something (operate against a bunch of something) Deal with output (format, export, etc) Functions should rarely include internal filtering, sorting, etc – output objects and let PowerShell’s native cmdlets do that Scripts shouldn’t be 900 lines that do 50 things – break each task down into a discrete function, and then call the functions
  • 13. PowerShell Proverbs Every time someone writes a PowerShell command that outputs text instead of objects, God kills a puppy. Harsh, but true. Output objects. There are a variety of syntaxes for doing so – I’ve used the one that most people find readable and concise.
  • 14. Thank You! Please feel free to hit me up with any remaining questions between sessions Please submit a session evaluation! These are an extremely important part of ensuring that the conference continues to provide you with the education you need! Resources and URLs on the next slide…
  • 15. Remember! Slides, and scripts will be posted within a few days. You’re welcome to download whatever you like; please don’t re-post anything elsewhere on the Internet. For the download URL, see my Twitter feed: @concentrateddon Twitter.com/concentrateddon
  • 16. More PowerShell Resources Web Sites ShellHub.com Bit.ly/DonJones YouTube.com/ ConcentratedDon ITPro. ConcentratedTech.com Thank you again for attending! Available Here!

Editor's Notes

  • #2: TechMentor Las Vegas 2011
  • #3: TechMentor Las Vegas 2011