Building PowerShell Modules
Building PowerShell Modules
An in-depth guide from design to production
About the Book
Are you a PowerShell scripter who wishes to take their skills to the next level? Have you ever wanted to create an open-source PowerShell module but didn't' know where to start? Then this book is for you!
Whether you are creating internal modules for your organization to use or open-source modules for the community to enjoy, you'll find something valuable in this book. This is not a "how to learn PowerShell" book. It is expected you already have the basics of PowerShell down, so things like PowerShell semantics and language features will not be the topic of this book. There are already some excellent books out there that cover the PowerShell language itself. I'd encourage you to take a look at those books first if you're interested in learning more about PowerShell as a language. Consider this book a follow-up to them where you will learn how to create useful, high-quality, and engaging PowerShell modules with real-world guidance, examples, and concept discussion.
This is an Agile-published book
Updates will be published as they are written. As PowerShell module practices evolve, so to will this book. Your one-time purchase grants you lifetime access to updates and any new content. You can even get notified via Leanpub (if you opt-in) when there's new content available, so you're always up to date.
As significant parts of the book are published, the price will increase accordingly. If you've already purchased a copy, then you're all set! You won't have to pay another dime, and you'll receive any updates for free. This is an excellent reason to purchase it now before it's finished to lock in the lower price.
The book will include four separate parts to cover high-level concepts. Each part will consist of dedicated topic chapters relevant to that concept.
- Part 1 - Modules Primer
- Part 2 - Project and Module Design
- Part 3 - The Build and Test Loop
- Part 4 - Creating a Quality Community Project
I love feedback. Use the "Email the Author(s)" link below to contact me. If something is unclear or you feel it is flat out wrong, let me know. All constructive feedback is welcome and ultimately creates a better book for everyone.
It truly is a book that fills a long-standing gap in topics from other PowerShell books. I have been asking other people for good material on module development for quite some time. This book is it.
- About the Author
About This Book
- PowerShell version
- Part 1
- Part 2
- Part 3
- Part 4
Part 1 - Modules Primer
1 Module Basics
- 1.1 What is a module
1.2 Why build modules
- 1.2.1 Organizing related functionality
- 1.2.2 Code sharing
- 1.2.3 Code reuse
- 1.2.4 Versioning
- 1.3 Terminology
1.4 Module types
- 1.4.1 Script modules
- 1.4.2 Binary modules
- 1.4.3 Manifest
- 1.4.4 What is a manifest
- 1.5 Summary
2 Working with Modules
2.1 Module locations
- 2.1.1 $env:PSModulePath
- 2.2.1 Finding modules online
- 2.2.2 Installing a module
- 2.2.3 Updating modules
- 2.2.4 Uninstalling modules
2.3 Discovering module information
- 2.3.1 Listing installed modules
- 2.3.2 Getting module commands
- 2.3.3 Exploring a module
2.4 Installing modules
- 2.4.1 Creating a hello world module
- 2.4.2 Manual installation
- 2.4.3 PowerShellGet
- 2.5 Saving modules
2.6 Importing modules
- 2.6.1 Modules are single-instance
- 2.6.2 Module prefixes
- 2.7 Being specific with module specifications
2.8 Module auto-loading
- 2.8.1 Controlling auto-loading behavior
2.9 Removing modules
- 2.9.1 Removing a module by name
- 2.9.2 Removing a module by using a module specification
- 2.9.3 Removing a module by PSModuleInfo
- 2.9.4 Caveats
- 2.10 Summary
- 2.1 Module locations
3 Authoring a Module
3.1 Basic structure of a module
- 3.1.1 Rules and conventions for module files
- 3.1.2 Exceptions to the rules
3.2 Creating a script module
- 3.2.1 Creating a basic script
- 3.2.2 Turning a script into a module
- 3.3.1 Manifest structure
- 3.3.2 Creating a module manifest
- 3.3.3 Elements of a manifest
- 3.3.4 Updating a manifest
- 3.3.5 Testing a manifest
- 3.4 Summary
- 3.1 Basic structure of a module
4 Dealing with Module Dependencies
4.1 Module dependencies
- 4.1.1 Implicit dependencies
- 4.1.2 Explicit dependencies
- 4.1.3 Focusing our efforts
- 4.1.4 Defining dependencies to other modules
- 4.1.5 Installing dependencies
- 4.2 Summary
- 4.1 Module dependencies
5 Distributing Modules
5.1 PowerShell repositories
- 5.1.1 The default repository
- 5.1.2 Trusting repositories
- 5.1.3 Repository types
5.2 Creating a local repository
- 5.2.1 Registering a repository
5.3 Publishing a module locally
- 5.3.1 Publishing a module by name
- 5.3.2 Publishing a module by file path
5.4 The PowerShell Gallery, a tour
- 5.4.1 Navigating the Gallery
- 5.4.2 Registering on the Gallery
- 5.4.3 Managing API keys
- 5.5 Summary
- 5.1 PowerShell repositories
- 1 Module Basics
Part 2 - Project and Module Design
6 Choosing a Module Layout
6.1 Monolithic PSM1
- 6.1.1 Module structure
6.2 Category submodules
- 6.2.1 Grouping by domain
6.3 Dot-sourced functions from PSM1
- 6.3.1 What happens during import
- 6.3.2 Advantages and disadvantages
- 6.4 Final verdict
- 6.5 Summary
- 6.1 Monolithic PSM1
7 Keeping Some Module Contents Private
7.1 Determining the public functions
- 7.1.1 The role of private functions
- 7.1.2 Candidates for private functions
- 7.1.3 Controlling the visibility of variables and aliases
- 7.2 Summary
- 7.1 Determining the public functions
8 Using Classes in a Module
8.1 Importing classes
- 8.1.1 The using statement
- 8.1.2 Differences from Import-Module
- 8.1.3 Differences from #requires
8.2 Using classes internally in a module
- 8.2.1 Trying to dot-source classes
- 8.3 Ordering classes
8.4 Extending classes from other modules
- 8.4.1 Having a module references classes from another module
8.5 The user experience of classes
- 8.5.1 Providing functions to create class instances
- 8.6 Summary
- 8.1 Importing classes
9 Building a Module From Many Files
- 9.1 Benefits of a monolithic PSM1
- 9.2 Benefits of dot-sourced functions
- 9.3 Creating a dot-sourced module
9.4 Building a module - E pluribus enum (out of many, one)
- 9.4.1 Creating a project directory
- 9.4.2 Creating a build script
- 9.4.3 Running the build script
- 9.4.4 Exporting functions in the manifest
- 9.5 Summary
10 Versioning a Module
10.1 What is a software version
- 10.1.1 Examples of versioning schemes
10.2 Semantic Versioning
- 10.2.1 SemVer rules
- 10.2.2 Why SemVer is useful
10.3 Automating module versioning
- 10.3.1 Avoid auto-incrementing
- 10.3.2 Incrementing a module version
10.4 Pre-release versioning
- 10.4.1 Adding a pre-release moniker
- 10.4.2 Publishing a pre-release module
- 10.4.3 Finding and installing a pre-release module
- 10.5 Tips for avoiding breaking changes
10.6 Handling deprecation
- 10.6.1 Communication avenues
10.7 Specifying compatible operating systems and PowerShell editions
- 10.7.1 The CompatiblePSEditions module manifest field
- 10.8 Summary
- 10.1 What is a software version
11 Building Better Functions
11.1 Plan your dive, dive your plan
- 11.1.1 Planning your functions
- 11.1.2 Think about the experience
- 11.2 Functions should do one thing
- 11.3 Creating testable functions
- 11.4 Self-contained functions
11.5 Writing defensive functions
- 11.5.1 Enforce mandatory parameters
- 11.5.2 Explicitly define parameter types
- 11.5.3 Use validation attributes
- 11.6 Document your functions
- 11.7 Adhere to approved verbs
- 11.8 Use proper parameter names
- 11.9 Use advanced functions
- 11.10 Support the pipeline
11.11 Create safe functions
11.11.1 Adding -WhatIf and
-Confirmto your functions
- 11.11.2 Using the -Force
- 11.11.1 Adding -WhatIf and
11.12 Sensible error handling
- 11.12.1 Creating terminating errors
- 11.12.2 Creating non-terminating errors
11.13 Write with cross-platform in mind
- 11.13.1 Working with the PATH environment variable
- 11.13.2 File paths and delimiters
- 11.14 Summary
- 11.1 Plan your dive, dive your plan
- 12 Elements of a Quality GitHub Project
- 13 Documenting a Project
- 6 Choosing a Module Layout
- Part 3 - The Build and Test Loop
- Part 4 - Creating a Quality Community Project
14 PowerShell Classes Explained
- 14.1 What is a PowerShell Class
- 14.2 Why use classes
- 14.3 Defining and creating a class
- 14.4 Adding class properties
- 14.5 Defining class methods
- 14.6 Initializing class properties
- 14.7 Validating properties by using attributes
- 14.8 Accessing the class members with $this
- 14.9 Passing input to methods
- 14.10 Method overloading and signatures
14.11 Making properties and methods static
- 14.11.1 Accessing static properties
- 14.11.2 Calling static methods
- 14.12 Initializing a class instance with constructors
- 14.13.1 Creating a derived class
- 14.13.2 Overriding methods
- 14.13.3 Calling base methods
- 14.13.4 Calling constructors
- 14.14 Hiding properties and methods
- 14.15.1 Using a enumeration
- 14.15.2 Using enumerations in parameters
- 14.15.3 Creating a enumeration
- 14.15.4 Flag enumerations
- 14.16 Summary
- 14 PowerShell Classes Explained
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
C++ Best PracticesJason Turner
Level up your C++, get the tools working for you, eliminate common problems, and move on to more exciting things!
Functional Design and ArchitectureAlexander Granin
Software Design in Functional Programming, Design Patterns and Practices, Methodologies and Application Architectures. How to build real software in Haskell with less efforts and low risks. The first complete source of knowledge.
OpenIntro StatisticsDavid Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntro
A complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
R Programming for Data ScienceRoger D. Peng
This book brings the fundamentals of R programming to you, using the same material developed as part of the industry-leading Johns Hopkins Data Science Specialization. The skills taught in this book will lay the foundation for you to begin your journey learning data science. Printed copies of this book are available through Lulu.
C++20 is the next big C++ standard after C++11. As C++11 did it, C++20 changes the way we program modern C++. This change is, in particular, due to the big four of C++20: ranges, coroutines, concepts, and modules.
I am a Software Engineer and I am in ChargeAlexis Monville and Michael Doyle
I am a Software Engineer and I am in Charge is a real-world, practical book that helps you increase your impact and satisfaction at work no matter who you work with.
In the book, we will follow Sandrine, a fictional character who learns to think in a new way enabling her to take a different course of action.
Invest In Digital Health - The Medical Futurist's GuideDr. Bertalan Mesko
Artificial Intelligence and Digital Health are booming. In this book, we explain why now it's a good time to invest in Digital Health and give recommendations on where to invest by looking at the top 24 technological trends we find the most promising.
Atomic KotlinBruce Eckel and Svetlana Isakova
For both beginning and experienced programmers! From the author of the multi-award-winning Thinking in C++ and Thinking in Java together with a member of the Kotlin language team comes a book that breaks the concepts into small, easy-to-digest "atoms," along with exercises supported by hints and solutions directly inside IntelliJ IDEA!
The Hundred-Page Machine Learning BookAndriy Burkov
Everything you really need to know in Machine Learning in a hundred pages.
Mastering STM32Carmine Noviello
With more than 600 microcontrollers, STM32 is probably the most complete ARM Cortex-M platform on the market. This book aims to be the first guide around that introduces the reader to this exciting MCU portfolio from ST Microelectronics and its official CubeHAL.
Software Architecture for Developers: Volumes 1 & 2 - Technical leadership and communication
2 Books"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before...
The Future of Digital Health
6 BooksWe put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy and how technology giants such as Amazon or Google want to conquer...
Cisco CCNA 200-301 Complet
4 BooksCe lot comprend les quatre volumes du guide préparation à l'examen de certification Cisco CCNA 200-301.
CCDE Practical Studies (All labs)
3 BooksCCDE lab
"The C++ Standard Library" and "Concurrency with Modern C++"
2 BooksGet my books "The C++ Standard Library" and "Concurrency with Modern C++" in a bundle. The first book gives you the details you should know about the C++ standard library; the second one dives deeper into concurrency with modern C++. In sum, you get more than 600 pages full of modern C++ and about 250 source files presenting the standard library...
Modern Management Made Easy
3 BooksRead all three Modern Management Made Easy books. Learn to manage yourself, lead and serve others, and lead the organization.
Programming with Ease
3 BooksAlle drei Bände der Serie Programming with Ease in einem Paket. Darin findest du alles, was ich dir zu den wichtigsten Phasen der Softwareentwicklung im Hinblick auf Clean Code Development für langfristig hohe Produktivität sagen kann.Im Band Slicing findest du die Anforderungsanalyse im Rahmen eines iterativ-inkrementellen Vorgehensmodells aus...
2 BooksUnveil the power of Ansible and Vagrant with this bundle at a special price. You'll have everything you need to get started with Vagrant - learn the basics and how to create your virtual development environments, using Ansible as provisioner! About Vagrant Cookbook Vagrant Cookbook is a complete guide to get started with Vagrant and create your...
2 BooksDocker and Kubernetes are taking the world by storm! These books will get you up-to-speed fast! Docker Deep Dive is over 400 pages long, and covers all objectives on the Docker Certified Associate exam.The Kubernetes Book includes everything you need to get up and running with Kubernetes!
Growing Agile: The Complete Coach's Guide
7 BooksGrowing Agile: Coach's Guide Series This bundle provides a collection of training and workshop plans for a variety of agile topics. The series is aimed at agile coaches, trainers and ScrumMasters who often find themselves needing to help teams understand agile concepts. Each book in the series provides the plans, slides, handouts and activity...