Chapter 7: Adding commands
Introduces PowerShell’s extensibility through its growing set of commands for Azure products.
After this chapter you will be able to
- PowerShell command extensibility. Explain that PowerShell can gain commands for more products as Microsoft develops them, including Azure services typically managed through the Azure portal.
- Modules as command extensions. Explain that PowerShell can gain commands through extensions called modules, much as a smartphone app can add a voice-assistant command without an operating-system upgrade.
- Repository discovery and management. Describe how PowerShellGet works with repositories: Register-PSRepository adds one, Find-Module searches for modules, Install-Module installs one, and Update-Module gets a newer version. Explain how the Gallery's module page helps check PowerShell Core testing and installation requirements.
- Installation and availability check. Describe the Az example: run Install-Module -Name Az, respond to the Gallery trust prompt, and use Get-Module -ListAvailable to verify installation because the module is not yet loaded.
- Module search paths. Explain that PSModulePath lists the locations where PowerShell looks for modules, including locations for system, shared, and personal modules. Describe what to do when a module is elsewhere.
- Module autodiscovery and autoloading. Describe how PowerShell can discover commands, offer completion and help, and load a module when its command is run without the user first loading that module.
- Product-specific command prefixes. Explain why most PowerShell extensions add a short prefix to the noun in their command names, as in Get-GcSqlInstance or Get-AzStorageTable.
- Exploring an unfamiliar module. Describe how the authors use help to find a command for making a zip archive, then load its module and list the other available commands. Explain why they load the module manually even though PowerShell could load it automatically.
- Creating a zip archive. Describe what the authors check before trying Compress-Archive and how they test it on a file.
- Finding help for module commands. Explain how to find a relevant command in a large module and learn to use it: narrow the list with Help or Get-Command and wildcards, then read the command’s help with -Example or -Full.
What it builds on
- Using help to find commands (chapter 3) · Finding commands with PowerShell’s help system.
- Optional and mandatory parameters (chapter 3) · Recognizing mandatory parameters in command help.
- Finding command examples (chapter 3) · Finding command examples in help.
Section by section
Introduction
Introduces PowerShell’s extensibility through its growing set of commands for Azure products.
- PowerShell command extensibility: Explain that PowerShell can gain commands for more products as Microsoft develops them, including Azure services typically managed through the Azure portal.
Why it matters: PowerShell’s commands are not limited to a fixed set of products.
Key terms: extensibility, commands, Azure portal
7.1 How one shell can do everything
This section explains how PowerShell can gain new commands through modules, using smartphone apps as an analogy.
- Modules as command extensions: Explain that PowerShell can gain commands through extensions called modules, much as a smartphone app can add a voice-assistant command without an operating-system upgrade.
Why it matters: This gives you a way to think about where additional PowerShell commands come from.
Key terms: modules, commands, extensions
7.2 Extensions: Finding and installing modules
This section explains what PowerShell modules are and how to find, install, update, and verify modules from online repositories.
- PowerShell module extensions: Explain that PowerShell v6 and newer use modules as their extension type, and that modules are designed to be self-contained and easier to distribute.
Why it matters: It clarifies what kind of extension you are looking for when adding commands. - Repository discovery and management: Describe how PowerShellGet works with repositories: Register-PSRepository adds one, Find-Module searches for modules, Install-Module installs one, and Update-Module gets a newer version. Explain how the Gallery's module page helps check PowerShell Core testing and installation requirements.
Why it matters: These are the starting points for finding a suitable module and keeping it current. - Installation and availability check: Describe the Az example: run Install-Module -Name Az, respond to the Gallery trust prompt, and use Get-Module -ListAvailable to verify installation because the module is not yet loaded.
Why it matters: The availability check lets you confirm installation without mistaking an unloaded module for a missing one. - Gallery code caution: Explain why a module appearing in the Microsoft-run PowerShell Gallery should not be treated as Microsoft-verified or endorsed.
Why it matters: A familiar repository name is not a guarantee that its contributed code is safe to run.
Key terms: module, snap-in, PowerShellGet, PowerShell Gallery, Register-PSRepository, Find-Module, Install-Module, Update-Module, Install-Module -Name Az, Get-Module
7.3 Extensions: Finding and adding modules
This section explains how PowerShell finds modules through PSModulePath, makes their commands available automatically, and handles modules outside those paths.
- Module search paths: Explain that PSModulePath lists the locations where PowerShell looks for modules, including locations for system, shared, and personal modules. Describe what to do when a module is elsewhere.
Why it matters: A module’s location determines whether PowerShell can find it automatically. - Module autodiscovery and autoloading: Describe how PowerShell can discover commands, offer completion and help, and load a module when its command is run without the user first loading that module.
Why it matters: You can find and try installed commands without manually importing every module first. - Google Cloud module exception: Describe why the GoogleCloud module needs an explicit import after installation and what that import triggers.
Why it matters: This example shows that a module requiring first-use input may not follow the usual autodiscovery experience.
Key terms: PSModulePath, Import-Module, system modules, shared, personal modules, autodiscovery, autoloading, Tab, IntelliSense, Update-Help
7.4 Command conflicts and removing extensions
This section explains how command prefixes prevent module naming conflicts and how to access or remove commands when conflicts occur.
- Product-specific command prefixes: Explain why most PowerShell extensions add a short prefix to the noun in their command names, as in Get-GcSqlInstance or Get-AzStorageTable.
Why it matters: Prefixes help you recognize which extension a command belongs to and avoid name collisions. - Same-name command resolution: Describe what happens when two loaded modules contain a command with the same name and how to call the other command specifically.
Why it matters: A naming conflict does not make the earlier command unavailable. - Module conflict remedies: Describe how to unload a conflicting module and how to supply a prefix when importing one.
Why it matters: You can address a conflict either by unloading a module or by giving imported commands distinct names.
Key terms: prefix, noun, command conflicts, module name, command name, Get-User, Remove-Module, Import-Module, -Prefix
7.5 Playing with a new module
The section demonstrates how to explore an unfamiliar PowerShell module and use its Compress-Archive command to create a zip file.
- Exploring an unfamiliar module: Describe how the authors use help to find a command for making a zip archive, then load its module and list the other available commands. Explain why they load the module manually even though PowerShell could load it automatically.
Why it matters: This gives you a way to teach yourself about commands for a new task. - Creating a zip archive: Describe what the authors check before trying Compress-Archive and how they test it on a file.
Why it matters: Checking required parameters lets you try a newly discovered command without guessing its inputs. - Verbose output and overwriting: Explain why the authors retry the command with -Verbose and -Force, including what each switch does in this example.
Why it matters: These switches make the retry informative and allow it to replace the archive from the first run.
Key terms: help system, Microsoft.PowerShell.Archive, module, Compress-Archive, -Path, -DestinationPath, mandatory parameters, -Verbose, -Force
7.6 Common points of confusion
This section explains how to avoid getting lost among module commands by narrowing the command list and reading detailed help, especially examples.
- Finding help for module commands: Explain how to find a relevant command in a large module and learn to use it: narrow the list with Help or Get-Command and wildcards, then read the command’s help with -Example or -Full.
Why it matters: This approach makes a large set of new module commands manageable and helps you use the command you find.
Key terms: modules, Help, Get-Command, wildcards, -Example, -Full
7.7 Lab
7.8 Lab answers
Where this is used later
- Finding the commands (chapter 9) · Finding and installing modules.
- Working with Azure PowerShell (chapter 10) · Installing a PowerShell module
- Ideas for further exploration (chapter 27) · Finding and installing PowerShell modules
- Learning to use the commands (chapter 9) · Learning to use the commands relies on reading their help.
Concepts explained in this chapter
- Install-ModuleInstall-Module is a PowerShell cmdlet that downloads and installs PowerShell modules from a package repository.
- Import-ModuleImport-Module is a PowerShell cmdlet that loads a module into the current session from a module name or path.
- moduleA module is a packaged unit of reusable code and related resources that can be loaded into a software environment.
- PowerShell GalleryPowerShell Gallery is an online repository for discovering and distributing PowerShell modules, scripts, and related packages.
- Get-CommandGet-Command is a PowerShell cmdlet that retrieves commands matching specified names, verbs, nouns, or command types.
- Get-HelpHelp is a PowerShell command that displays help content for commands and other PowerShell elements.
- full helpFull help is the detailed help view for a PowerShell command, including comprehensive parameter descriptions and metadata.
- wildcardA wildcard is a pattern-matching character or expression that represents one or more possible characters in a name or search.
- Get-ModuleGet-Module is a PowerShell cmdlet that lists or retrieves information about modules available in or loaded into a session.
- -expandproperty-ExpandProperty is a Select-Object parameter that outputs the values of a specified property instead of objects containing that property.
- commandA command is an executable instruction that a shell can invoke to perform an operation.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
