SlideShare a Scribd company logo
Convert Your Brain from VBScript to PowerShell 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
Change Your Brain VBScript is a  scripting language PowerShell is a  shell  that has some  scripting capabilities In many cases you can do a line-by-line conversion from VBScript to PowerShell – but you ’re not taking advantage of PowerShell’s strengths We ’re going to look at some specific scenarios and try to change your brain!  ‱ Don Jones ‱ ConcentratedTech.com
The Language PowerShell ’s “scripting language” is about 14 keywords It provides most of the language constructs you know from VBScript Let ’s look at where to find the help on them, because we aren’t really going to focus on them a lot here We  will  look at Switch because it ’s so different from Select Case  ‱ Don Jones ‱ ConcentratedTech.com
Changing Your Brain GOOD If & Switch – good for adding conditional commands in complex processes AVOID ForEach – if you ’re enumerating a collection, you’re likely doing it wrong Loops of any kind – often not needed, and a sign of a  “VBS” approach rather than a “PSH” approach  ‱ Don Jones ‱ ConcentratedTech.com
Example #1 Reading a list of computer names and connecting to them via WMI We ’ll look at a VBS-style approach, and then a more compact PowerShell-style approach
Example #2 Combining info from multiple sources into a single table Again, VBS approach first – then a couple of PowerShell-style approaches  ‱ Don Jones ‱ ConcentratedTech.com
The Trick with PowerShell PowerShell commands  intrinsically  provide collection enumeration within the pipeline Many PowerShell command parameters  natively  accept collections/arrays (how can you tell?) so you don ’t have to enumerate over the collection/array yourself (Parens) let you embed embed entire commands as input to another command ’s parameters Many commands can accept  other  commands as parameters  ‱ Don Jones ‱ ConcentratedTech.com
Stop Producing Text Never use Write-Host. Write-Output  to the pipeline  – and write objects, not text Also: Write-Debug ($DebugPreference) Write-Error Write-Warning Write-Verbose Produce  objects  ‱ Don Jones ‱ ConcentratedTech.com
Modularization, the PowerShell Way Every unit – script, function, whatever – should do  one  thing and either: Produce NO output Produce ONE consistent kind of output to the pipeline Utilize verb-noun naming convention Use consistent parameter names Create functions designed to work within the pipeline (ideally,  “script cmdlets” or Advanced Functions) Add help using comments  ‱ Don Jones ‱ ConcentratedTech.com
Never Do This Produce a list
 
 output it to a text file
 
 and then read that back in and parse it. Text is only to be used as a  final output  – not an intermediary Never try to parse the output of a table (e.g., Format-Table) – here ’s why  ‱ Don Jones ‱ ConcentratedTech.com
Where are my functions?!? PowerShell doesn ’t have intrinsic data-manipulation functions Instead, look at methods of
 String objects DateTime objects Also look at the static methods of the [Math] class, e.g., [Math]::Abs(-5)  ‱ Don Jones ‱ ConcentratedTech.com
Any Questions?  & Closing Thoughts Use the pipeline. The pipeline isn ’t a feature of PowerShell, it’s at the heart and soul of how the shell is structured For a lot of tasks, a command sequence ( “pipeline”) can be a lot shorter than a VBScript – and just as effective Think  reusability  – output objects, since those have maximum re-use.  ‱ 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 at  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)

PPTX
PowerShell crashcourse for sharepoint
Concentrated Technology
 
PPT
Prepping software for w7 deployment
Concentrated Technology
 
PPTX
PowerShell custom properties
Concentrated Technology
 
PPTX
Virtualization auditing & security deck v1.0
Concentrated Technology
 
PPT
Rapidly deploying software
Concentrated Technology
 
PPT
Wsus sample scripts
Concentrated Technology
 
PPTX
Vdi in-a-box
Concentrated Technology
 
PDF
UKLUG 2012 - XPages, Beyond the basics
Ulrich Krause
 
PPTX
NMS Media Services Jobshet 1 to 5 Summary
Hock Leng PUAH
 
KEY
Builder webinar
Adam Christian
 
PPTX
Pantheon basics
Plasterdog Web Design
 
KEY
Features, Exportables & You
jskulski
 
PDF
Docker bdxio
Nicolas De Loof
 
PPT
Crossover
szlwzl
 
PDF
DevOps Fest 2020. immutable infrastructure as code. True story.
Vlad Fedosov
 
PDF
ColdFusion for Penetration Testers
Chris Gates
 
PPTX
CollabSphere SC 103 : Domino on the Web : Yes, It's (Probably) Hackable
Darren Duke
 
PPTX
Meet Windows PowerShell
Concentrated Technology
 
PDF
Automated Tasks for WordPress
Joe Cartonia
 
PPTX
A crash course in scaling wordpress
GovLoop
 
PowerShell crashcourse for sharepoint
Concentrated Technology
 
Prepping software for w7 deployment
Concentrated Technology
 
PowerShell custom properties
Concentrated Technology
 
Virtualization auditing & security deck v1.0
Concentrated Technology
 
Rapidly deploying software
Concentrated Technology
 
Wsus sample scripts
Concentrated Technology
 
Vdi in-a-box
Concentrated Technology
 
UKLUG 2012 - XPages, Beyond the basics
Ulrich Krause
 
NMS Media Services Jobshet 1 to 5 Summary
Hock Leng PUAH
 
Builder webinar
Adam Christian
 
Pantheon basics
Plasterdog Web Design
 
Features, Exportables & You
jskulski
 
Docker bdxio
Nicolas De Loof
 
Crossover
szlwzl
 
DevOps Fest 2020. immutable infrastructure as code. True story.
Vlad Fedosov
 
ColdFusion for Penetration Testers
Chris Gates
 
CollabSphere SC 103 : Domino on the Web : Yes, It's (Probably) Hackable
Darren Duke
 
Meet Windows PowerShell
Concentrated Technology
 
Automated Tasks for WordPress
Joe Cartonia
 
A crash course in scaling wordpress
GovLoop
 

Viewers also liked (17)

PPTX
Best free tools for win database admin
Concentrated Technology
 
PPT
PowerShell Functions
mikepfeiffer
 
PPTX
Best free tools for w d a
Concentrated Technology
 
PPTX
PowerShell crash course
Concentrated Technology
 
KEY
PowerShell and the Future of Windows Automation
Concentrated Technology
 
PPT
Free tools for win server administration
Concentrated Technology
 
PPTX
VDI-in-a-Box: Microsoft Desktop Virtualization for Smaller Businesses and Uses
Concentrated Technology
 
PPT
PowerShell v4 Desired State Configuration
Jason Stangroome
 
PPT
Ad disasters & how to prevent them
Concentrated Technology
 
PPTX
Three cool cmdlets I wish PowerShell Had!
Thomas Lee
 
PPTX
Implementing dr w. hyper v clustering
Concentrated Technology
 
PPTX
Introduction to powershell
Salaudeen Rajack
 
PPT
Ha & drs gotcha's
Concentrated Technology
 
PPTX
Basic PowerShell Toolmaking - Spiceworld 2016 session
Rob Dunn
 
PPT
Automating ad with powershell
Concentrated Technology
 
PPTX
Managing enterprise with PowerShell remoting
Concentrated Technology
 
PPT
No-script PowerShell v2
Concentrated Technology
 
Best free tools for win database admin
Concentrated Technology
 
PowerShell Functions
mikepfeiffer
 
Best free tools for w d a
Concentrated Technology
 
PowerShell crash course
Concentrated Technology
 
PowerShell and the Future of Windows Automation
Concentrated Technology
 
Free tools for win server administration
Concentrated Technology
 
VDI-in-a-Box: Microsoft Desktop Virtualization for Smaller Businesses and Uses
Concentrated Technology
 
PowerShell v4 Desired State Configuration
Jason Stangroome
 
Ad disasters & how to prevent them
Concentrated Technology
 
Three cool cmdlets I wish PowerShell Had!
Thomas Lee
 
Implementing dr w. hyper v clustering
Concentrated Technology
 
Introduction to powershell
Salaudeen Rajack
 
Ha & drs gotcha's
Concentrated Technology
 
Basic PowerShell Toolmaking - Spiceworld 2016 session
Rob Dunn
 
Automating ad with powershell
Concentrated Technology
 
Managing enterprise with PowerShell remoting
Concentrated Technology
 
No-script PowerShell v2
Concentrated Technology
 
Ad

Similar to From VB Script to PowerShell (20)

PPT
PowerShell Scripting and Modularization (TechMentor Fall 2011)
Concentrated Technology
 
PPTX
Learn from my Mistakes - Building Better Solutions in SPFx
Thomas Daly
 
PPTX
Admin SharePoint 2010 with PowerShell
Concentrated Technology
 
PPTX
Holy PowerShell, BATman! - dogfood edition
Dave Diehl
 
PPTX
Learning to be IDE Free (PrDC 2015)
David Wesst
 
PDF
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
Evan Mullins
 
PPT
CSS Adnaved with HTML abd complete Stylesheet
PraveenHegde20
 
PPTX
Professional Help for PowerShell Modules
June Blender
 
PPTX
Advanced PowerShell Automation
kieranjacobsen
 
PDF
JavaScript guide 2020 Learn JavaScript
Laurence Svekis ✔
 
PPT
C#.net
AllsoftSolutions
 
PPTX
Creating and Maintaining an Open Source Library
Nicholas Schweitzer
 
PPTX
Untangling spring week11
Derek Jacoby
 
PDF
CS4200 2019 Lecture 1: Introduction
Eelco Visser
 
PPTX
BDD with SpecFlow and Selenium
Liraz Shay
 
PPT
Case study
karan saini
 
PDF
How to guarantee your change is integrated to Moodle core
Dan Poltawski
 
PDF
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
Pallavi Sharma
 
PPTX
Untangling6
Derek Jacoby
 
PPTX
O365 Developer Bootcamp NJ 2018 - Material
Thomas Daly
 
PowerShell Scripting and Modularization (TechMentor Fall 2011)
Concentrated Technology
 
Learn from my Mistakes - Building Better Solutions in SPFx
Thomas Daly
 
Admin SharePoint 2010 with PowerShell
Concentrated Technology
 
Holy PowerShell, BATman! - dogfood edition
Dave Diehl
 
Learning to be IDE Free (PrDC 2015)
David Wesst
 
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
Evan Mullins
 
CSS Adnaved with HTML abd complete Stylesheet
PraveenHegde20
 
Professional Help for PowerShell Modules
June Blender
 
Advanced PowerShell Automation
kieranjacobsen
 
JavaScript guide 2020 Learn JavaScript
Laurence Svekis ✔
 
Creating and Maintaining an Open Source Library
Nicholas Schweitzer
 
Untangling spring week11
Derek Jacoby
 
CS4200 2019 Lecture 1: Introduction
Eelco Visser
 
BDD with SpecFlow and Selenium
Liraz Shay
 
Case study
karan saini
 
How to guarantee your change is integrated to Moodle core
Dan Poltawski
 
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
Pallavi Sharma
 
Untangling6
Derek Jacoby
 
O365 Developer Bootcamp NJ 2018 - Material
Thomas Daly
 
Ad

More from Concentrated Technology (11)

PPTX
Wsus best practices
Concentrated Technology
 
PPT
Virtualization today
Concentrated Technology
 
PPT
Top ESXi command line v2.0
Concentrated Technology
 
PPT
Securely connecting to apps over the internet using rds
Concentrated Technology
 
PPTX
PowerShell and WMI
Concentrated Technology
 
PPT
Managing SQLserver
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
 
PPT
How to configure esx to pass an audit
Concentrated Technology
 
Wsus best practices
Concentrated Technology
 
Virtualization today
Concentrated Technology
 
Top ESXi command line v2.0
Concentrated Technology
 
Securely connecting to apps over the internet using rds
Concentrated Technology
 
PowerShell and WMI
Concentrated Technology
 
Managing SQLserver
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
 
How to configure esx to pass an audit
Concentrated Technology
 

Recently uploaded (20)

PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PPTX
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
PPTX
Wondershare Filmora Crack Free Download 2025
josanj305
 
PDF
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
PPTX
Reimaginando la Ciberdefensa: De Copilots a Redes de Agentes
Cristian Garcia G.
 
PDF
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PDF
“A Re-imagination of Embedded Vision System Design,” a Presentation from Imag...
Edge AI and Vision Alliance
 
PDF
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
PDF
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
PDF
Quantum Threats Are Closer Than You Think – Act Now to Stay Secure
WSO2
 
PDF
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
PPTX
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
PDF
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PDF
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 
PDF
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
Wondershare Filmora Crack Free Download 2025
josanj305
 
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
Reimaginando la Ciberdefensa: De Copilots a Redes de Agentes
Cristian Garcia G.
 
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
“A Re-imagination of Embedded Vision System Design,” a Presentation from Imag...
Edge AI and Vision Alliance
 
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
Quantum Threats Are Closer Than You Think – Act Now to Stay Secure
WSO2
 
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 

From VB Script to PowerShell

  • 1. Convert Your Brain from VBScript to PowerShell 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. Change Your Brain VBScript is a scripting language PowerShell is a shell that has some scripting capabilities In many cases you can do a line-by-line conversion from VBScript to PowerShell – but you ’re not taking advantage of PowerShell’s strengths We ’re going to look at some specific scenarios and try to change your brain! ‱ Don Jones ‱ ConcentratedTech.com
  • 5. The Language PowerShell ’s “scripting language” is about 14 keywords It provides most of the language constructs you know from VBScript Let ’s look at where to find the help on them, because we aren’t really going to focus on them a lot here We will look at Switch because it ’s so different from Select Case ‱ Don Jones ‱ ConcentratedTech.com
  • 6. Changing Your Brain GOOD If & Switch – good for adding conditional commands in complex processes AVOID ForEach – if you ’re enumerating a collection, you’re likely doing it wrong Loops of any kind – often not needed, and a sign of a “VBS” approach rather than a “PSH” approach ‱ Don Jones ‱ ConcentratedTech.com
  • 7. Example #1 Reading a list of computer names and connecting to them via WMI We ’ll look at a VBS-style approach, and then a more compact PowerShell-style approach
  • 8. Example #2 Combining info from multiple sources into a single table Again, VBS approach first – then a couple of PowerShell-style approaches ‱ Don Jones ‱ ConcentratedTech.com
  • 9. The Trick with PowerShell PowerShell commands intrinsically provide collection enumeration within the pipeline Many PowerShell command parameters natively accept collections/arrays (how can you tell?) so you don ’t have to enumerate over the collection/array yourself (Parens) let you embed embed entire commands as input to another command ’s parameters Many commands can accept other commands as parameters ‱ Don Jones ‱ ConcentratedTech.com
  • 10. Stop Producing Text Never use Write-Host. Write-Output to the pipeline – and write objects, not text Also: Write-Debug ($DebugPreference) Write-Error Write-Warning Write-Verbose Produce objects ‱ Don Jones ‱ ConcentratedTech.com
  • 11. Modularization, the PowerShell Way Every unit – script, function, whatever – should do one thing and either: Produce NO output Produce ONE consistent kind of output to the pipeline Utilize verb-noun naming convention Use consistent parameter names Create functions designed to work within the pipeline (ideally, “script cmdlets” or Advanced Functions) Add help using comments ‱ Don Jones ‱ ConcentratedTech.com
  • 12. Never Do This Produce a list
 
 output it to a text file
 
 and then read that back in and parse it. Text is only to be used as a final output – not an intermediary Never try to parse the output of a table (e.g., Format-Table) – here ’s why ‱ Don Jones ‱ ConcentratedTech.com
  • 13. Where are my functions?!? PowerShell doesn ’t have intrinsic data-manipulation functions Instead, look at methods of
 String objects DateTime objects Also look at the static methods of the [Math] class, e.g., [Math]::Abs(-5) ‱ Don Jones ‱ ConcentratedTech.com
  • 14. Any Questions? & Closing Thoughts Use the pipeline. The pipeline isn ’t a feature of PowerShell, it’s at the heart and soul of how the shell is structured For a lot of tasks, a command sequence ( “pipeline”) can be a lot shorter than a VBScript – and just as effective Think reusability – output objects, since those have maximum re-use. ‱ 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 at 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.