-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Windows 11 for Enterprise Administrators
By :

In PowerShell, you use commands to have PowerShell carry out some operation, whether it be displaying a file, adding a user to Active Directory, or setting the IP address of a computer.
In PowerShell, a command is something you can run from a script file or at the console that performs some operation. There are several types of PowerShell commands:
.ps1
.In addition, the term command also applies to the many Win32 console applications, shipped with Windows 11 (over 300). Many of these are familiar to IT professionals, such as ipconfig.exe
and ping.exe
).
All PowerShell commands can accept and produce objects. The Win32 console applications, on the other hand, only take parameters (which tend to be unique to each console application) and output a string.
Console applications are very useful, although they can be harder to use in an automation scenario. If you need to, you can capture the output of a console application and use string manipulation to pull out the specific information you need. This approach, often called prayer-based parsing, is common in the Unix/Linux world. PowerShell objects make this process easier, and in most cases, there are PowerShell commands that can replace old console applications.
In PowerShell, a module contains a set of PowerShell commands, module metadata, and other information (such as help or formatting information). Before using any PowerShell command, PowerShell first loads the module containing that command.
By default, if you use a command in a module stored in one of a set of well-known folders, PowerShell automatically loads the module and then executes the command. Powershell has several default locations from which to load modules. The Windows PSModulePath
environment variable defines PowerShell’s paths to discover and load modules (by default). Every time PowerShell starts up, it examines the current value of the module path variable and determines all the commands available (in those locations). This process creates a cache of all commands and which module to use.
For example, to use the Get-Process
command to view all the running processes, PowerShell needs to load the Microsoft.PowerShell.Management
module. This is the module that contains this command. Once PowerShell loads the module, it can execute the command.
Each time PowerShell starts up, it caches the location of every command in every module (for those modules located in one of those well-known places). This means that, in most cases, you only need to type a command, and the rest of the magic happens behind the scenes. You can put a module into any location on the disk and manually load it using Import-Module
.
You can get modules from a variety of places:
No matter where you get them from, modules are a critical component of PowerShell that help the authors of PowerShell package and ship their PowerShell modules.
If you want to learn more about building your own PowerShell 7 module, see https://packt.link/wvznY.
In PowerShell, the term discovery means using built-in commands to find information on how to use PowerShell and PowerShell commands. The more you can discover, the less you need to memorize. Discovery is an extremely useful feature that the PowerShell team designed in the first versions and refined later. Without discovery, using thousands of commands and hundreds of potential modules would be much more difficult.
There are four key aspects of discovery within PowerShell:
Get-Module -ListAvailable
cmdlet to see all the modules that PowerShell can discover on your host. You can also use Find-Module
to find the modules contained in the PowerShell Gallery that may be interesting.Get-Command
and specifying the module name like this:Figure 2.11 – Discovering commands in a module
Get-Help
, as noted earlier, helps you to work out what a cmdlet, function, or script does. For example, you can determine more details of the Start-BitsTransfer
command like this:Figure 2.12 – Getting help on a cmdlet
The help text gives you more details about what a command does.
Get-VM
to determine the VMs on your host.Figure 2.13 – Getting the members of a class
These four discovery approaches help you use PowerShell – to find modules and commands, determine what a PowerShell command does, and establish which outputs, if any, result.
Change the font size
Change margin width
Change background colour