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
 
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)

PPTX
PowerShell 101
Thomas Lee
 
PDF
Sql Server & PowerShell
Aaron Shilo
 
PPTX
PowerShell for Penetration Testers
Nikhil Mittal
 
PDF
Windows Powershell in Action 1st Edition Bruce G. Payette
zahithovor
 
PDF
Windows Powershell in Action 1st Edition Bruce G. Payette
moudenongui20
 
PPTX
Everything you need to know about PowerShell
Shane Hoey
 
PDF
Powershell training material
Dr. Awase Khirni Syed
 
PDF
Windows Powershell in Action 1st Edition Bruce G. Payette
takabedembe
 
PPT
PowerShell Core Skills (TechMentor Fall 2011)
Concentrated Technology
 
PPT
Powershell Seminar @ ITWorx CuttingEdge Club
Essam Salah
 
PDF
powershell.pdf
Saurabh846965
 
PDF
Power Shell For Testers
Mca140 software solutions
 
PPTX
PowerShell-1
Saravanan G
 
PDF
PowerShell in Depth An administrator s guide Don Jones
lekwalakha3p
 
PPT
PowerShell Scripting and Modularization (TechMentor Fall 2011)
Concentrated Technology
 
PPTX
Introduction to PowerShell and getting started
Ravikanth Chaganti
 
PPT
Introduction to PowerShell
Salaudeen Rajack
 
PPTX
Holy PowerShell, BATman! - dogfood edition
Dave Diehl
 
PDF
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
ClapperboardCinemaPV
 
PPTX
learn ps new advance for all powershell.pptx
Ronnie Kapoor
 
PowerShell 101
Thomas Lee
 
Sql Server & PowerShell
Aaron Shilo
 
PowerShell for Penetration Testers
Nikhil Mittal
 
Windows Powershell in Action 1st Edition Bruce G. Payette
zahithovor
 
Windows Powershell in Action 1st Edition Bruce G. Payette
moudenongui20
 
Everything you need to know about PowerShell
Shane Hoey
 
Powershell training material
Dr. Awase Khirni Syed
 
Windows Powershell in Action 1st Edition Bruce G. Payette
takabedembe
 
PowerShell Core Skills (TechMentor Fall 2011)
Concentrated Technology
 
Powershell Seminar @ ITWorx CuttingEdge Club
Essam Salah
 
powershell.pdf
Saurabh846965
 
Power Shell For Testers
Mca140 software solutions
 
PowerShell-1
Saravanan G
 
PowerShell in Depth An administrator s guide Don Jones
lekwalakha3p
 
PowerShell Scripting and Modularization (TechMentor Fall 2011)
Concentrated Technology
 
Introduction to PowerShell and getting started
Ravikanth Chaganti
 
Introduction to PowerShell
Salaudeen Rajack
 
Holy PowerShell, BATman! - dogfood edition
Dave Diehl
 
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
ClapperboardCinemaPV
 
learn ps new advance for all powershell.pptx
Ronnie Kapoor
 
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)

PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PDF
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
PPTX
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
PPTX
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
PDF
Next level data operations using Power Automate magic
Andries den Haan
 
PDF
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
PDF
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PDF
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
PDF
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
PDF
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
PDF
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
PDF
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
PDF
Kubernetes - Architecture & Components.pdf
geethak285
 
PDF
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
PPTX
The birth and death of Stars - earth and life science
rizellemarieastrolo
 
PDF
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
Next level data operations using Power Automate magic
Andries den Haan
 
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
Practical Applications of AI in Local Government
OnBoard
 
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
Kubernetes - Architecture & Components.pdf
geethak285
 
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
The birth and death of Stars - earth and life science
rizellemarieastrolo
 
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 

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.