
How it works…
Hundreds of modules, scripts, and Desired State Configuration resources have been registered with the PSGallery repository. Microsoft now recommends using this repository for module management. Using the Find-Module cmdlet, PowerShell makes a connection to the repository and gets a list of all available modules. Then, it runs a search on the returned results based on the criteria you mention.
You can also find scripts that can perform repetitive tasks. To find scripts, use the Find-Script cmdlet. It works similar to the Find-Module cmdlet, except that it finds individual scripts rather than modules.
Installation of modules is a simple process of pulling the modules down from the repository, similar to npm or chocolatey. These tasks are taken care of by the PowerShellGet module, which ships with PowerShell. Installing, updating, and uninstalling PowerShell modules may require elevated privileges.
To load the capabilities of a module into the PowerShell session, use Import-Module. PowerShell modules have members such as cmdlets, functions, aliases, and so on for sessions. Import-Module loads these members into the session. By default, the sessions are unloaded when exiting the session. However, if you would like to manually unload them, use the Remove-Module cmdlet. Remove-Module does not remove the entire module; it just unloads it.
The modules are installed in one of the $env:PsModulePath directories. You don't need to specify the path to modules that are installed this way. If the module files are saved elsewhere, you will need to specify the path to the module's psd1 or psm1 file when calling Import-Module. Also, some modules enable automated loading. Just call a cmdlet from the module, and the module will auto-import.
Import-Module has parameters such as -Prefix and -NoClobber. The -Prefix parameter adds the specified prefix to the nouns of all of the cmdlets in the module. For instance, Import-Module docker -pre dm will import the Docker cmdlets as Invoke-dmDockerCommand instead of Invoke-DockerCommand. The -NoClobber switch helps in cases where there may be cmdlet name conflicts; it prevents the already loaded cmdlets from being replaced by the ones from the module being imported.