SlideShare a Scribd company logo
M o d e r n i z i n g Po w e r S h e l l S c r i p t s
whoami
• Matthias van den Elsacker
• Axxes since 2014
• System Engineer @ Umicore since 2014
• First Line for 1 year
• Second/Third Line SCCM for 4 years
• Network Engineer @ Umicore since 2019
• Contact: Matthias.vandenElsacker@axxes.com
Introduction
Why this session
My Collection of Scripts
Where did I leave these again?
Problem? Solution!
Talking points
• Best practices
• PowerShell to PowerShell Core
• Cross Platform
• ISE to Visual Studio Code
• Git
• Pester
Best Practices
And style rules
lowercase, PascalCase, UPPERCASE
• lowercase: Powershell Keywords
• foreach, switch, return, -eq, -like,…
• PascalCase: All public identifiers
• Functions, Modules, Cmdlets, Attributes, Classes,…
• Do-Something, $SomeVariable, MyModule.psm1,…
• UPPERCASE: Comment-based help keywords
• .SYNOPSIS, .EXAMPLE, .DESCRIPTION,…
“One True Brace Style”
• Brackets open at the end of a line.
• Brackets close at the beginning of a line.
• Exception: short CommandBlocks.
Verb-Noun
• All PowerShell Modules, Functions and Cmdlets follow this rule.
• Get-Process, New-LocalUser, Clear-Content,…
• Follow this rule when creating functions.
• Repair-Wmi, Add-DomainUserToLocalAdmins, Get-
RootCertificatesFromComputer
• List of approved Verbs:
• Get-Verb
Modernizing PowerShell Scripts
Aliases
• Aliases are cool and all, but…
• … make code hard to understand.
• So try to avoid them.
• (Unless you are playing Code Golf)
Comments
• Comments should be useful.
• Not useful:
• Useful:
Other Best Practices
Modernizing PowerShell Scripts
Modernizing PowerShell Scripts
Modernizing PowerShell Scripts
Modernizing PowerShell Scripts
Other Best Practices
• Re-usability
Modernizing PowerShell Scripts
Modernizing PowerShell Scripts
Other Best Practices
• Re-usability
• Modularity
Modernizing PowerShell Scripts
Modernizing PowerShell Scripts
Other Best Practices
• Re-usability
• Modularity
• Don’t re-invent the wheel
Modernizing PowerShell Scripts
Other Best Practices
• Re-usability
• Modularity
• Don’t re-invent the wheel
• Write-*
PowerShell to PS Core
Moving to an open-source, cross-platform version
Modernizing PowerShell Scripts
What’s broken?
Solution!
What’s broken?
Solution!
What’s broken?
Solution!
Solution!
What’s broken?
Solution?
PowerShell Core keeps evolving…
What about Linux?
Cross-Platform PowerShell
PowerShell comes in a lot of flavors
Remote Connection to Linux
Remote Connection to Linux
Windows vs Linux
ISE vs Code
Out with the old, in with the new
In Memoriam
Welcome Visual Studio Code
Main advantages
• Workspaces, folders, and files
• Add-ons
• Themes
• Cross Platform
• Debugging
• Multiple terminals
• Integrated GIT
• Not just for PowerShell
• It’s just cooler
Git
And GitHub for System Engineers
“A solution for growing pains”
G-I-T
• Random three-letter combination that is pronounceable, and not actually
used by any common UNIX command. The fact that it is a
mispronunciation of "get" may or may not be relevant.
• Stupid. Contemptible and Despicable. Simple. Take your pick from the
dictionary of slang.
• “Global information tracker": you're in a good mood, and it actually works
for you. Angels sing, and a light suddenly fills the room.
• “Goddamn idiotic truckload of sh*t": when it breaks
Modernizing PowerShell Scripts
Modernizing PowerShell Scripts
Pester
Testing PowerShell, using PowerShell
Pester
• Test Framework
• For PowerShell
• Written in PowerShell
• DSL Syntax:
• “Describe”
• “It”
• “Should”
Type of Tests
• Unit Testing
• In isolation (using $TestDrive)
• No external code (using Mocks)
• Integration Testing
• “White/Clear Box Testing”
• Integration with external code
• Acceptance Testing
• “Black Box Testing”
• Third party
T h a n k y o u !
Resources
• https://github.com/PoshCode/PowerShellPracticeAndStyle
• https://poshcode.gitbooks.io/powershell-practice-and-style/
• https://docs.microsoft.com/en-us/powershell/scripting/whats-new/breaking-changes-ps6?view=powershell-6
• https://4sysops.com/archives/make-visual-studio-code-look-and-behave-like-powershell-ise/
• https://docs.microsoft.com/en-us/powershell/scripting/learn/remoting/ssh-remoting-in-powershell-
core?view=powershell-6
• https://github.com/PowerShell/psl-omi-provider
• https://lkml.org/lkml/1998/9/30/122
• https://guides.github.com/activities/hello-world/
• https://github.com/pester/Pester
• https://www.red-gate.com/simple-talk/sysadmin/powershell/introduction-to-testing-your-powershell-code-with-
pester/

More Related Content

PDF
DEF CON 23 - Rich Kelley - harness powershell weaponization made easy
PDF
Crafting interactive troubleshooting guides and team documentation for your K...
PDF
Paint it blue with PowerShell
PPTX
Azure CLI 2.0 Tips and Tricks
PPT
Jira and Confluence - How the company behind those products works - Anatoli K...
PDF
Innovating with Mozilla Labs
PDF
Apply chat automation today - work smarter tomorrow
PPTX
Selenium 101 Webinar
DEF CON 23 - Rich Kelley - harness powershell weaponization made easy
Crafting interactive troubleshooting guides and team documentation for your K...
Paint it blue with PowerShell
Azure CLI 2.0 Tips and Tricks
Jira and Confluence - How the company behind those products works - Anatoli K...
Innovating with Mozilla Labs
Apply chat automation today - work smarter tomorrow
Selenium 101 Webinar

What's hot (20)

PDF
Stable Squeak World Tour
PPTX
On premise cross-browser testing
PPTX
Azure Bicep - An Introduction
PDF
Immutable infrastructure with Boxfuse
PDF
The Architect Way - JSCamp.asia 2012
PDF
Playing with playgrounds
PPTX
Goodbye Flash, Hello OpenFL: Next Generation Cross-Platform Game Development
PDF
The Three Musketeers
PPTX
Generalization in Auto-Testing. How we put what we had into new Technological...
PPTX
Azure at the command line
PDF
Game Programming 00 - Exams
PDF
Open.source.innovation.20070624
PDF
Docker
PDF
Meet the Selenium Grid
PDF
Wilko Nienhaus - continuous delivery release the right thing, done right, at ...
PDF
Perl-Critic
PPTX
Go Fast, Go Safe, Go on Vacation - Compuware ISPW Webcast
PPTX
Power shell v3 session1
PPTX
Final presentation
PPTX
Docker and Jenkins Pipeline
Stable Squeak World Tour
On premise cross-browser testing
Azure Bicep - An Introduction
Immutable infrastructure with Boxfuse
The Architect Way - JSCamp.asia 2012
Playing with playgrounds
Goodbye Flash, Hello OpenFL: Next Generation Cross-Platform Game Development
The Three Musketeers
Generalization in Auto-Testing. How we put what we had into new Technological...
Azure at the command line
Game Programming 00 - Exams
Open.source.innovation.20070624
Docker
Meet the Selenium Grid
Wilko Nienhaus - continuous delivery release the right thing, done right, at ...
Perl-Critic
Go Fast, Go Safe, Go on Vacation - Compuware ISPW Webcast
Power shell v3 session1
Final presentation
Docker and Jenkins Pipeline
Ad

Similar to Modernizing PowerShell Scripts (20)

PPTX
Holy PowerShell, BATman! - dogfood edition
PPTX
Professional Help for PowerShell Modules
PPTX
Microsoft ASP.NET 5 - The new kid on the block
PPTX
It's XP Stupid (2019)
PDF
PPTX
Extreme Programming (XP): Revisted
PDF
It's XP, Stupid
PPT
David buksbaum a-briefintroductiontocsharp
PPTX
Вредные советы .NET разработчикам, Сергей Калинец
PPTX
PowerShell 101 - What is it and Why should YOU Care!
PPTX
Coding Standard And Code Review
PDF
What we talk about when we talk about DevOps
PPTX
ASP.NET 5 - Microsoft's Web development platform reimagined
PPTX
.NET per la Data Science e oltre
PDF
DSL's with Groovy
PPS
CS101- Introduction to Computing- Lecture 45
KEY
Driving application development through behavior driven development
PDF
August Webinar - Water Cooler Talks: A Look into a Developer's Workbench
PPTX
PowerShell for Penetration Testers
PPTX
Hidden Treasure - TestComplete Script Extensions
Holy PowerShell, BATman! - dogfood edition
Professional Help for PowerShell Modules
Microsoft ASP.NET 5 - The new kid on the block
It's XP Stupid (2019)
Extreme Programming (XP): Revisted
It's XP, Stupid
David buksbaum a-briefintroductiontocsharp
Вредные советы .NET разработчикам, Сергей Калинец
PowerShell 101 - What is it and Why should YOU Care!
Coding Standard And Code Review
What we talk about when we talk about DevOps
ASP.NET 5 - Microsoft's Web development platform reimagined
.NET per la Data Science e oltre
DSL's with Groovy
CS101- Introduction to Computing- Lecture 45
Driving application development through behavior driven development
August Webinar - Water Cooler Talks: A Look into a Developer's Workbench
PowerShell for Penetration Testers
Hidden Treasure - TestComplete Script Extensions
Ad

More from Axxes IT Consultancy (6)

PDF
Slides blockchain sessies Kristof verslype
PPTX
Axxes tax hackers
PDF
Security Basics - Internet Safety
PDF
Futureproof angular 1.x applications - yannick houbrix
PDF
Pitfalls in Performance Testing AxxesCC 06/2015
PPTX
Axxes software development traineeship
Slides blockchain sessies Kristof verslype
Axxes tax hackers
Security Basics - Internet Safety
Futureproof angular 1.x applications - yannick houbrix
Pitfalls in Performance Testing AxxesCC 06/2015
Axxes software development traineeship

Recently uploaded (20)

PDF
Empathic Computing: Creating Shared Understanding
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
A Presentation on Artificial Intelligence
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
Empathic Computing: Creating Shared Understanding
Building Integrated photovoltaic BIPV_UPV.pdf
Spectral efficient network and resource selection model in 5G networks
Unlocking AI with Model Context Protocol (MCP)
Per capita expenditure prediction using model stacking based on satellite ima...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
“AI and Expert System Decision Support & Business Intelligence Systems”
MYSQL Presentation for SQL database connectivity
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Big Data Technologies - Introduction.pptx
Network Security Unit 5.pdf for BCA BBA.
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Diabetes mellitus diagnosis method based random forest with bat algorithm
A Presentation on Artificial Intelligence
Encapsulation_ Review paper, used for researhc scholars
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
A comparative analysis of optical character recognition models for extracting...
NewMind AI Weekly Chronicles - August'25-Week II

Modernizing PowerShell Scripts