SlideShare a Scribd company logo
Windows PowerShell Scripting & Modularization 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
Agenda Start with a Command Move to a Script Parameterize the Script Encapsulate in a Function Using Dot-Sourcing More Complex: Pipeline Functions Adding Help Building a Script Module Making a  “Script Cmdlet”  • Don Jones • ConcentratedTech.com
WARNING: FIREHOSE MODE I ’m going to be moving quickly through some seriously complex stuff Rely on the downloadable scripts  as your reference – while you ’re listening to me, the concepts are more important. This is a lot to cover in 75 minutes.  Consider this an introduction to capabilities – that you ’ll explore in more detail on your own. Don’t try to memorize right now!  • Don Jones • ConcentratedTech.com
Start with a Command Get the command working in the shell, first. Easier to debug – immediate feedback.  • Don Jones • ConcentratedTech.com
Move to a Script Paste commands into a script. Done.  • Don Jones • ConcentratedTech.com
Parameterize the Script Add a PARAM() block to define parameters Replace hardcoded, changeable information with parameters Provide a data type ([string],[int], etc) and possibly a default Don ’t worry about making parameters “mandatory” or prompting at this point; we’ll evolve to that  • Don Jones • ConcentratedTech.com
Encapsulate in a Function Move parameter definition to inside a function Bonus: Don ’t output text. Never use Write-Host. Instead, create custom objects – enabled far better reusability.  • Don Jones • ConcentratedTech.com
Using Dot-Sourcing .  Path-to-Script Loads script into the current scope – functions remain defined after script exits Basically a way to  “include” the functions from one script into another, or into the global shell  • Don Jones • ConcentratedTech.com
More Complex: Pipeline Functions Includes BEGIN, PROCESS, and END script blocks With PROCESS, pipeline objects are placed into $_ placeholder Deal with one object at a time Hint: Add actual  “functionality” in a separate function… will make evolution easier  • Don Jones • ConcentratedTech.com
Adding Help Help about_comment_based* Specially-formatted comments can be parsed and presented as standardized help No need to define a –help or -? parameter yourself!  • Don Jones • ConcentratedTech.com
Building a Script Module Rename .ps1 and .psm1 to make it a Script Module Load using Import-Module – no need to dot-source All functions in module are automatically exposed You can also define aliases if desired Locate in …/Documents/WindowsPowerShell/Modules/ Module-name/module-name.psm1  for easier loading  • Don Jones • ConcentratedTech.com
Making a  “Script Cmdlet” Lets you formally specify parameters Parameters have attributes like Mandatory, validation, etc. Parameters can bind pipeline input PROCESS script block executes once for each object piped in; if multiple objects are given to a parameter WITHOUT using the pipeline, you ’ll need to manually enumerate Trick: Embed main functionality in a private function  • 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 More resources on  www.ShellHub.com   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

What's hot (20)

PowerShell crashcourse for Sharepoint admins
PowerShell crashcourse for Sharepoint adminsPowerShell crashcourse for Sharepoint admins
PowerShell crashcourse for Sharepoint admins
Concentrated Technology
 
PowerShell crashcourse for sharepoint
PowerShell crashcourse for sharepointPowerShell crashcourse for sharepoint
PowerShell crashcourse for sharepoint
Concentrated Technology
 
Rapidly deploying software
Rapidly deploying softwareRapidly deploying software
Rapidly deploying software
Concentrated Technology
 
Prepping software for w7 deployment
Prepping software for w7 deploymentPrepping software for w7 deployment
Prepping software for w7 deployment
Concentrated Technology
 
Virtualization auditing & security deck v1.0
Virtualization auditing & security deck v1.0Virtualization auditing & security deck v1.0
Virtualization auditing & security deck v1.0
Concentrated Technology
 
Top ESXi command line v2.0
Top ESXi command line v2.0Top ESXi command line v2.0
Top ESXi command line v2.0
Concentrated Technology
 
Vdi in-a-box
Vdi in-a-boxVdi in-a-box
Vdi in-a-box
Concentrated Technology
 
Wsus sample scripts
Wsus sample scriptsWsus sample scripts
Wsus sample scripts
Concentrated Technology
 
Builder webinar
Builder webinarBuilder webinar
Builder webinar
Adam Christian
 
NMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 SummaryNMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 Summary
Hock Leng PUAH
 
Crossover
CrossoverCrossover
Crossover
szlwzl
 
CollabSphere 2018 - Java in Domino After XPages
CollabSphere 2018 - Java in Domino After XPagesCollabSphere 2018 - Java in Domino After XPages
CollabSphere 2018 - Java in Domino After XPages
Jesse Gallagher
 
Docker bdxio
Docker bdxioDocker bdxio
Docker bdxio
Nicolas De Loof
 
IBM Connect 2014 BP204: It's Not Infernal: Dante's Nine Circles of XPages Heaven
IBM Connect 2014 BP204: It's Not Infernal: Dante's Nine Circles of XPages HeavenIBM Connect 2014 BP204: It's Not Infernal: Dante's Nine Circles of XPages Heaven
IBM Connect 2014 BP204: It's Not Infernal: Dante's Nine Circles of XPages Heaven
Paul Withers
 
Deploying w7
Deploying w7Deploying w7
Deploying w7
Concentrated Technology
 
J+s
J+sJ+s
J+s
happyuk
 
CollabSphere SC 103 : Domino on the Web : Yes, It's (Probably) Hackable
CollabSphere SC 103 : Domino on the Web : Yes, It's (Probably) HackableCollabSphere SC 103 : Domino on the Web : Yes, It's (Probably) Hackable
CollabSphere SC 103 : Domino on the Web : Yes, It's (Probably) Hackable
Darren Duke
 
How to Build a Pure Evil Magento Module
How to Build a Pure Evil Magento ModuleHow to Build a Pure Evil Magento Module
How to Build a Pure Evil Magento Module
AOE
 
PHP North-East - Automated Deployment
PHP North-East - Automated DeploymentPHP North-East - Automated Deployment
PHP North-East - Automated Deployment
Michael Peacock
 
ColdFusion for Penetration Testers
ColdFusion for Penetration TestersColdFusion for Penetration Testers
ColdFusion for Penetration Testers
Chris Gates
 
PowerShell crashcourse for Sharepoint admins
PowerShell crashcourse for Sharepoint adminsPowerShell crashcourse for Sharepoint admins
PowerShell crashcourse for Sharepoint admins
Concentrated Technology
 
Virtualization auditing & security deck v1.0
Virtualization auditing & security deck v1.0Virtualization auditing & security deck v1.0
Virtualization auditing & security deck v1.0
Concentrated Technology
 
NMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 SummaryNMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 Summary
Hock Leng PUAH
 
Crossover
CrossoverCrossover
Crossover
szlwzl
 
CollabSphere 2018 - Java in Domino After XPages
CollabSphere 2018 - Java in Domino After XPagesCollabSphere 2018 - Java in Domino After XPages
CollabSphere 2018 - Java in Domino After XPages
Jesse Gallagher
 
IBM Connect 2014 BP204: It's Not Infernal: Dante's Nine Circles of XPages Heaven
IBM Connect 2014 BP204: It's Not Infernal: Dante's Nine Circles of XPages HeavenIBM Connect 2014 BP204: It's Not Infernal: Dante's Nine Circles of XPages Heaven
IBM Connect 2014 BP204: It's Not Infernal: Dante's Nine Circles of XPages Heaven
Paul Withers
 
CollabSphere SC 103 : Domino on the Web : Yes, It's (Probably) Hackable
CollabSphere SC 103 : Domino on the Web : Yes, It's (Probably) HackableCollabSphere SC 103 : Domino on the Web : Yes, It's (Probably) Hackable
CollabSphere SC 103 : Domino on the Web : Yes, It's (Probably) Hackable
Darren Duke
 
How to Build a Pure Evil Magento Module
How to Build a Pure Evil Magento ModuleHow to Build a Pure Evil Magento Module
How to Build a Pure Evil Magento Module
AOE
 
PHP North-East - Automated Deployment
PHP North-East - Automated DeploymentPHP North-East - Automated Deployment
PHP North-East - Automated Deployment
Michael Peacock
 
ColdFusion for Penetration Testers
ColdFusion for Penetration TestersColdFusion for Penetration Testers
ColdFusion for Penetration Testers
Chris Gates
 

Viewers also liked (19)

Basic PowerShell Toolmaking - Spiceworld 2016 session
Basic PowerShell Toolmaking - Spiceworld 2016 sessionBasic PowerShell Toolmaking - Spiceworld 2016 session
Basic PowerShell Toolmaking - Spiceworld 2016 session
Rob Dunn
 
PowerShell crash course
PowerShell crash coursePowerShell crash course
PowerShell crash course
Concentrated Technology
 
Ive got a powershell secret
Ive got a powershell secretIve got a powershell secret
Ive got a powershell secret
Chris Conte
 
Best free tools for w d a
Best free tools for w d aBest free tools for w d a
Best free tools for w d a
Concentrated Technology
 
Free tools for win server administration
Free tools for win server administrationFree tools for win server administration
Free tools for win server administration
Concentrated Technology
 
Best free tools for win database admin
Best free tools for win database adminBest free tools for win database admin
Best free tools for win database admin
Concentrated Technology
 
Meet Windows PowerShell
Meet Windows PowerShellMeet Windows PowerShell
Meet Windows PowerShell
Concentrated Technology
 
Implementing dr w. hyper v clustering
Implementing dr w. hyper v clusteringImplementing dr w. hyper v clustering
Implementing dr w. hyper v clustering
Concentrated Technology
 
Automating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShellAutomating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShell
Concentrated Technology
 
Combining output from multiple sources
Combining output from multiple sourcesCombining output from multiple sources
Combining output from multiple sources
Concentrated Technology
 
PowerShell and the Future of Windows Automation
PowerShell and the Future of Windows AutomationPowerShell and the Future of Windows Automation
PowerShell and the Future of Windows Automation
Concentrated Technology
 
Advanced Tools & Scripting with PowerShell 3.0 Jump Start - Certificate
Advanced Tools & Scripting with PowerShell 3.0 Jump Start - CertificateAdvanced Tools & Scripting with PowerShell 3.0 Jump Start - Certificate
Advanced Tools & Scripting with PowerShell 3.0 Jump Start - Certificate
Don Reese
 
Automating ad with powershell
Automating ad with powershellAutomating ad with powershell
Automating ad with powershell
Concentrated Technology
 
PowerShell v4 Desired State Configuration
PowerShell v4 Desired State ConfigurationPowerShell v4 Desired State Configuration
PowerShell v4 Desired State Configuration
Jason Stangroome
 
Managing SQLserver
Managing SQLserverManaging SQLserver
Managing SQLserver
Concentrated Technology
 
Ha & drs gotcha's
Ha & drs gotcha'sHa & drs gotcha's
Ha & drs gotcha's
Concentrated Technology
 
VDI-in-a-Box: Microsoft Desktop Virtualization for Smaller Businesses and Uses
VDI-in-a-Box:  Microsoft Desktop Virtualization for Smaller Businesses and UsesVDI-in-a-Box:  Microsoft Desktop Virtualization for Smaller Businesses and Uses
VDI-in-a-Box: Microsoft Desktop Virtualization for Smaller Businesses and Uses
Concentrated Technology
 
Three cool cmdlets I wish PowerShell Had!
Three cool cmdlets I wish PowerShell Had!Three cool cmdlets I wish PowerShell Had!
Three cool cmdlets I wish PowerShell Had!
Thomas Lee
 
Managing enterprise with PowerShell remoting
Managing enterprise with PowerShell remotingManaging enterprise with PowerShell remoting
Managing enterprise with PowerShell remoting
Concentrated Technology
 
Basic PowerShell Toolmaking - Spiceworld 2016 session
Basic PowerShell Toolmaking - Spiceworld 2016 sessionBasic PowerShell Toolmaking - Spiceworld 2016 session
Basic PowerShell Toolmaking - Spiceworld 2016 session
Rob Dunn
 
Ive got a powershell secret
Ive got a powershell secretIve got a powershell secret
Ive got a powershell secret
Chris Conte
 
Free tools for win server administration
Free tools for win server administrationFree tools for win server administration
Free tools for win server administration
Concentrated Technology
 
Automating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShellAutomating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShell
Concentrated Technology
 
PowerShell and the Future of Windows Automation
PowerShell and the Future of Windows AutomationPowerShell and the Future of Windows Automation
PowerShell and the Future of Windows Automation
Concentrated Technology
 
Advanced Tools & Scripting with PowerShell 3.0 Jump Start - Certificate
Advanced Tools & Scripting with PowerShell 3.0 Jump Start - CertificateAdvanced Tools & Scripting with PowerShell 3.0 Jump Start - Certificate
Advanced Tools & Scripting with PowerShell 3.0 Jump Start - Certificate
Don Reese
 
PowerShell v4 Desired State Configuration
PowerShell v4 Desired State ConfigurationPowerShell v4 Desired State Configuration
PowerShell v4 Desired State Configuration
Jason Stangroome
 
VDI-in-a-Box: Microsoft Desktop Virtualization for Smaller Businesses and Uses
VDI-in-a-Box:  Microsoft Desktop Virtualization for Smaller Businesses and UsesVDI-in-a-Box:  Microsoft Desktop Virtualization for Smaller Businesses and Uses
VDI-in-a-Box: Microsoft Desktop Virtualization for Smaller Businesses and Uses
Concentrated Technology
 
Three cool cmdlets I wish PowerShell Had!
Three cool cmdlets I wish PowerShell Had!Three cool cmdlets I wish PowerShell Had!
Three cool cmdlets I wish PowerShell Had!
Thomas Lee
 
Managing enterprise with PowerShell remoting
Managing enterprise with PowerShell remotingManaging enterprise with PowerShell remoting
Managing enterprise with PowerShell remoting
Concentrated Technology
 
Ad

Similar to PS scripting and modularization (20)

PowerShell Scripting and Modularization (TechMentor Fall 2011)
PowerShell Scripting and Modularization (TechMentor Fall 2011)PowerShell Scripting and Modularization (TechMentor Fall 2011)
PowerShell Scripting and Modularization (TechMentor Fall 2011)
Concentrated Technology
 
PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)
Concentrated Technology
 
Power shell training
Power shell trainingPower shell training
Power shell training
David Brabant
 
PowerShell 101 - What is it and Why should YOU Care!
PowerShell 101 - What is it and Why should YOU Care!PowerShell 101 - What is it and Why should YOU Care!
PowerShell 101 - What is it and Why should YOU Care!
Thomas Lee
 
PowerShell for Penetration Testers
PowerShell for Penetration TestersPowerShell for Penetration Testers
PowerShell for Penetration Testers
Nikhil Mittal
 
powershell.pdf
powershell.pdfpowershell.pdf
powershell.pdf
Saurabh846965
 
Powershell notes
Powershell notesPowershell notes
Powershell notes
Carlos Amorim
 
Holy PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood editionHoly PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood edition
Dave Diehl
 
Powershell training material
Powershell training materialPowershell training material
Powershell training material
Dr. Awase Khirni Syed
 
Practical PowerShell Programming for Professional People - Extended Edition
Practical PowerShell Programming for Professional People - Extended EditionPractical PowerShell Programming for Professional People - Extended Edition
Practical PowerShell Programming for Professional People - Extended Edition
Ben Ten (0xA)
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101
Thomas Lee
 
Save Time With PowerCLI
Save Time With PowerCLISave Time With PowerCLI
Save Time With PowerCLI
jonathanmedd
 
Sql Server & PowerShell
Sql Server & PowerShellSql Server & PowerShell
Sql Server & PowerShell
Aaron Shilo
 
PowerShell In 2024 And Beyond The Future Of Automation.pdf
PowerShell In 2024 And Beyond The Future Of Automation.pdfPowerShell In 2024 And Beyond The Future Of Automation.pdf
PowerShell In 2024 And Beyond The Future Of Automation.pdf
DataSpace Academy
 
In just one hour i will make you a power shell ninja
In just one hour i will make you a power shell ninjaIn just one hour i will make you a power shell ninja
In just one hour i will make you a power shell ninja
Jason Brown
 
Introduction To Power Shell
Introduction To Power ShellIntroduction To Power Shell
Introduction To Power Shell
Ivan Suhinin
 
No-script PowerShell v2
No-script PowerShell v2No-script PowerShell v2
No-script PowerShell v2
Concentrated Technology
 
Everything you need to know about PowerShell
Everything you need to know about PowerShellEverything you need to know about PowerShell
Everything you need to know about PowerShell
Shane Hoey
 
PowerShell in Depth An administrator s guide Don Jones
PowerShell in Depth An administrator s guide Don JonesPowerShell in Depth An administrator s guide Don Jones
PowerShell in Depth An administrator s guide Don Jones
lekwalakha3p
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101
Thomas Lee
 
PowerShell Scripting and Modularization (TechMentor Fall 2011)
PowerShell Scripting and Modularization (TechMentor Fall 2011)PowerShell Scripting and Modularization (TechMentor Fall 2011)
PowerShell Scripting and Modularization (TechMentor Fall 2011)
Concentrated Technology
 
PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)
Concentrated Technology
 
Power shell training
Power shell trainingPower shell training
Power shell training
David Brabant
 
PowerShell 101 - What is it and Why should YOU Care!
PowerShell 101 - What is it and Why should YOU Care!PowerShell 101 - What is it and Why should YOU Care!
PowerShell 101 - What is it and Why should YOU Care!
Thomas Lee
 
PowerShell for Penetration Testers
PowerShell for Penetration TestersPowerShell for Penetration Testers
PowerShell for Penetration Testers
Nikhil Mittal
 
Holy PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood editionHoly PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood edition
Dave Diehl
 
Practical PowerShell Programming for Professional People - Extended Edition
Practical PowerShell Programming for Professional People - Extended EditionPractical PowerShell Programming for Professional People - Extended Edition
Practical PowerShell Programming for Professional People - Extended Edition
Ben Ten (0xA)
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101
Thomas Lee
 
Save Time With PowerCLI
Save Time With PowerCLISave Time With PowerCLI
Save Time With PowerCLI
jonathanmedd
 
Sql Server & PowerShell
Sql Server & PowerShellSql Server & PowerShell
Sql Server & PowerShell
Aaron Shilo
 
PowerShell In 2024 And Beyond The Future Of Automation.pdf
PowerShell In 2024 And Beyond The Future Of Automation.pdfPowerShell In 2024 And Beyond The Future Of Automation.pdf
PowerShell In 2024 And Beyond The Future Of Automation.pdf
DataSpace Academy
 
In just one hour i will make you a power shell ninja
In just one hour i will make you a power shell ninjaIn just one hour i will make you a power shell ninja
In just one hour i will make you a power shell ninja
Jason Brown
 
Introduction To Power Shell
Introduction To Power ShellIntroduction To Power Shell
Introduction To Power Shell
Ivan Suhinin
 
Everything you need to know about PowerShell
Everything you need to know about PowerShellEverything you need to know about PowerShell
Everything you need to know about PowerShell
Shane Hoey
 
PowerShell in Depth An administrator s guide Don Jones
PowerShell in Depth An administrator s guide Don JonesPowerShell in Depth An administrator s guide Don Jones
PowerShell in Depth An administrator s guide Don Jones
lekwalakha3p
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101
Thomas Lee
 
Ad

More from Concentrated Technology (9)

Wsus best practices
Wsus best practicesWsus best practices
Wsus best practices
Concentrated Technology
 
Virtualization today
Virtualization todayVirtualization today
Virtualization today
Concentrated Technology
 
PowerShell custom properties
PowerShell custom propertiesPowerShell custom properties
PowerShell custom properties
Concentrated Technology
 
PowerShell and WMI
PowerShell and WMIPowerShell and WMI
PowerShell and WMI
Concentrated Technology
 
Managing SQLserver for the reluctant DBA
Managing SQLserver for the reluctant DBAManaging SQLserver for the reluctant DBA
Managing SQLserver for the reluctant DBA
Concentrated Technology
 
Inventory your network and clients with PowerShell
Inventory your network and clients with PowerShellInventory your network and clients with PowerShell
Inventory your network and clients with PowerShell
Concentrated Technology
 
Iis implementation
Iis implementationIis implementation
Iis implementation
Concentrated Technology
 
Hyper v r2 deep dive
Hyper v r2 deep diveHyper v r2 deep dive
Hyper v r2 deep dive
Concentrated Technology
 
How to configure esx to pass an audit
How to configure esx to pass an auditHow to configure esx to pass an audit
How to configure esx to pass an audit
Concentrated Technology
 

Recently uploaded (20)

SDG 9000 Series: Unleashing multigigabit everywhere
SDG 9000 Series: Unleashing multigigabit everywhereSDG 9000 Series: Unleashing multigigabit everywhere
SDG 9000 Series: Unleashing multigigabit everywhere
Adtran
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...
pranavbodhak
 
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath InsightsUiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPathCommunity
 
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Nikki Chapple
 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
 
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AI Emotional Actors:  “When Machines Learn to Feel and Perform"AI Emotional Actors:  “When Machines Learn to Feel and Perform"
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AkashKumar809858
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 
Droidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing HealthcareDroidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing Healthcare
Droidal LLC
 
Contributing to WordPress With & Without Code.pptx
Contributing to WordPress With & Without Code.pptxContributing to WordPress With & Without Code.pptx
Contributing to WordPress With & Without Code.pptx
Patrick Lumumba
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
Let’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack CommunityLet’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack Community
SanjeetMishra29
 
Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025
Prasta Maha
 
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure ModesCognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Dr. Tathagat Varma
 
Gihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai TechnologyGihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai Technology
zainkhurram1111
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
Co-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using ProvenanceCo-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using Provenance
Paul Groth
 
Microsoft Build 2025 takeaways in one presentation
Microsoft Build 2025 takeaways in one presentationMicrosoft Build 2025 takeaways in one presentation
Microsoft Build 2025 takeaways in one presentation
Digitalmara
 
SDG 9000 Series: Unleashing multigigabit everywhere
SDG 9000 Series: Unleashing multigigabit everywhereSDG 9000 Series: Unleashing multigigabit everywhere
SDG 9000 Series: Unleashing multigigabit everywhere
Adtran
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...
pranavbodhak
 
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath InsightsUiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPathCommunity
 
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Nikki Chapple
 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
 
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AI Emotional Actors:  “When Machines Learn to Feel and Perform"AI Emotional Actors:  “When Machines Learn to Feel and Perform"
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AkashKumar809858
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 
Droidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing HealthcareDroidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing Healthcare
Droidal LLC
 
Contributing to WordPress With & Without Code.pptx
Contributing to WordPress With & Without Code.pptxContributing to WordPress With & Without Code.pptx
Contributing to WordPress With & Without Code.pptx
Patrick Lumumba
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
Let’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack CommunityLet’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack Community
SanjeetMishra29
 
Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025
Prasta Maha
 
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure ModesCognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Dr. Tathagat Varma
 
Gihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai TechnologyGihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai Technology
zainkhurram1111
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
Co-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using ProvenanceCo-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using Provenance
Paul Groth
 
Microsoft Build 2025 takeaways in one presentation
Microsoft Build 2025 takeaways in one presentationMicrosoft Build 2025 takeaways in one presentation
Microsoft Build 2025 takeaways in one presentation
Digitalmara
 

PS scripting and modularization

  • 1. Windows PowerShell Scripting & Modularization 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. Agenda Start with a Command Move to a Script Parameterize the Script Encapsulate in a Function Using Dot-Sourcing More Complex: Pipeline Functions Adding Help Building a Script Module Making a “Script Cmdlet” • Don Jones • ConcentratedTech.com
  • 5. WARNING: FIREHOSE MODE I ’m going to be moving quickly through some seriously complex stuff Rely on the downloadable scripts as your reference – while you ’re listening to me, the concepts are more important. This is a lot to cover in 75 minutes. Consider this an introduction to capabilities – that you ’ll explore in more detail on your own. Don’t try to memorize right now! • Don Jones • ConcentratedTech.com
  • 6. Start with a Command Get the command working in the shell, first. Easier to debug – immediate feedback. • Don Jones • ConcentratedTech.com
  • 7. Move to a Script Paste commands into a script. Done. • Don Jones • ConcentratedTech.com
  • 8. Parameterize the Script Add a PARAM() block to define parameters Replace hardcoded, changeable information with parameters Provide a data type ([string],[int], etc) and possibly a default Don ’t worry about making parameters “mandatory” or prompting at this point; we’ll evolve to that • Don Jones • ConcentratedTech.com
  • 9. Encapsulate in a Function Move parameter definition to inside a function Bonus: Don ’t output text. Never use Write-Host. Instead, create custom objects – enabled far better reusability. • Don Jones • ConcentratedTech.com
  • 10. Using Dot-Sourcing . Path-to-Script Loads script into the current scope – functions remain defined after script exits Basically a way to “include” the functions from one script into another, or into the global shell • Don Jones • ConcentratedTech.com
  • 11. More Complex: Pipeline Functions Includes BEGIN, PROCESS, and END script blocks With PROCESS, pipeline objects are placed into $_ placeholder Deal with one object at a time Hint: Add actual “functionality” in a separate function… will make evolution easier • Don Jones • ConcentratedTech.com
  • 12. Adding Help Help about_comment_based* Specially-formatted comments can be parsed and presented as standardized help No need to define a –help or -? parameter yourself! • Don Jones • ConcentratedTech.com
  • 13. Building a Script Module Rename .ps1 and .psm1 to make it a Script Module Load using Import-Module – no need to dot-source All functions in module are automatically exposed You can also define aliases if desired Locate in …/Documents/WindowsPowerShell/Modules/ Module-name/module-name.psm1 for easier loading • Don Jones • ConcentratedTech.com
  • 14. Making a “Script Cmdlet” Lets you formally specify parameters Parameters have attributes like Mandatory, validation, etc. Parameters can bind pipeline input PROCESS script block executes once for each object piped in; if multiple objects are given to a parameter WITHOUT using the pipeline, you ’ll need to manually enumerate Trick: Embed main functionality in a private function • Don Jones • ConcentratedTech.com
  • 15. 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 More resources on www.ShellHub.com Thank you very much! • Don Jones • ConcentratedTech.com
  • 16. 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.