Most PowerShell commands live in modules, and by adding new modules, you can add new commands to your PowerShell environment. To find out whether a command lives in a module, use Get-Command. The next line returns the module that ships the command Get-Service:
PS C:\> Get-Command -Name Get-Service | Select-Object -ExpandProperty Module
If the Module property is empty, then the command does not ship via a module. This is true for all non-PowerShell commands such as applications:
PS C:\> Get-Command -Name notepad | Select-Object -ExpandProperty Module
Next, let’s list all modules available on your system:
PS> Get-Module -ListAvailable | Select-Object -Property Name, Path
If you take a closer look at the results, you’ll notice that Get-Module lists more than one folder. The default module folders recognized by PowerShell are specified in $env:PSModulePath which is a semicolon-separated list, similar to $env:Path for applications:
PS> $env:PSModulePath C:\Users\tobia\OneDrive\Dokumente\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C: \Windows\system32\WindowsPowerShell\v1.0\Modules PS> $env:PSModulePath -split ';' C:\Users\tobia\OneDrive\Dokumente\WindowsPowerShell\Modules C:\Program Files\WindowsPowerShell\Modules C:\Windows\system32\WindowsPowerShell\v1.0\Modules
If you’d like to explore the content of a specific module, look for the Path property: it typically points to a .psd1 data file with the module meta data. This is where the module version and copyright are specified, and typically its RootModule entry specifies the code for the module. If it is a module built with PowerShell code, this is a .psm1 file, else a binary DLL.
To examine the module content, open its parent folder in Windows Explorer. For example, the next line opens the “PrintManagement” module in Windows Explorer (provided it is present on your machine):
PS> Get-Module -Name PrintManagement -ListAvailable | Select-Object -ExpandProperty Path | Split-Path C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PrintManagement PS> explorer (Get-Module -Name PrintManagement -ListAvailable | Select-Object -ExpandProperty Path | Split-Path)
This quick walk-through explains why PowerShell does not have a fixed command set, and why a given command may be available on one system and missing on another. New modules can be introduced by the operating system (Windows 10 ships with many more modules than Windows 7, for example), by software you have installed (i.e. SQL Server), by roles you have activated (i.e. Domain Controller), and modules can also be installed manually.
This line for example installs a free module from the public PowerShell Gallery that adds useful new commands to create all kinds of QR codes:
PS C:\> Install-Module -Name QRCodeGenerator -Scope CurrentUser -Force
Once the module is installed, you get new commands like this one which creates a QR code for Twitter profiles:
PS C:\> New-QRCodeTwitter -ProfileName tobiaspsp -Show
To see all the commands shipped by a given module, try this:
PS C:\> Get-Command -Module QRCodeGenerator CommandType Name Version Source ----------- ---- ------- ------ Function New-QRCodeGeolocation 1.2 QRCodeGenerator Function New-QRCodeTwitter 1.2 QRCodeGenerator Function New-QRCodeVCard 1.2 QRCodeGenerator Function New-QRCodeWifiAccess 1.2 QRCodeGenerator