This document discusses modernizing PowerShell scripts by following best practices, moving scripts from Windows PowerShell to cross-platform PowerShell Core, switching from the PowerShell ISE to Visual Studio Code integrated development environment, using Git for version control, and testing scripts with Pester. Some highlighted best practices include using PascalCase for identifiers, following a verb-noun naming convention, avoiding aliases, and writing reusable, modular code. The benefits of PowerShell Core, Visual Studio Code, Git, and Pester for testing scripts are also summarized.
1. 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
2. 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
10. “One True Brace Style”
• Brackets open at the end of a line.
• Brackets close at the beginning of a line.
• Exception: short CommandBlocks.
11. 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
12.
13. Aliases
• Aliases are cool and all, but…
• … make code hard to understand.
• So try to avoid them.
• (Unless you are playing Code Golf)
52. 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
56. Pester
• Test Framework
• For PowerShell
• Written in PowerShell
• DSL Syntax:
• “Describe”
• “It”
• “Should”
57. 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