How it works...
In step 1, you start by reviewing the cmdlets in the PowerShellGet module:
In steps 2-7, you ensure PowerShellGet and its dependency PackageManagement are up to date by updating the NuGet provider, verifying the version, then restarting your PowerShell session and updating PowerShellGet and verifying its version.
The -Verbose flag gives you more details on the installation, but it is not required. Note that you must Exit your session after running this command and reopen to continue with the latest version.
Check our NuGet provider version after reopening our PowerShell session:
In step 6-7, you update the PowerShellGetmodule:
Note that you must exit your session after running this command and reopen to continue with the latest version.
In step 8, check your PowerShellGet version after reopening your PowerShell session:
In step 9, you use Get-PSRepository. PowerShellGet starts with a single repository PSGallery installed by default:
In step 10, review the package providers available:
Note the source column; the first three providers listed correspond to NuGet, OneGet, and Chocolatey providers. NuGet is a repository devoted to developer libraries. OneGet was the name of this module (and repository) but has been deprecated and replaced by PackageManagement. You explore Chocolatey in a later recipe. The remaining rows are the available providers in the PSGallery repository.
In step 11, you limit your repository search with Find-PSRepository by specifying the -Source PSGallery parameter:
In step 12, you discover the PowerShellGet commands containing the verb Find:
In steps 13 - 18, you use the Find-* commands to store the available commands, modules, DSC resources, and scripts into variables, then explore what is available using Out-GridView (including using the built-in filter capability to search for a module), for example:
In step 19, you review the install commands in the PowerShellGet module. Their functions are very similar:
In step 20, the TreeSize module looks like an interesting tool to inspect folders and their sizes. Install it by using the Install-Module cmdlet. You use the -Verbose switch to get more information about what the cmdlet is doing:
After confirming the Untrusted repository pop up dialog, PowerShell installs the module.
In step 21, you see that the code available on PSGallery, as well as other public repositories, is just that, public. You must choose to trust the code you download from the internet to take advantage of the functionality provided by that code. To trust this repository and disable prompting, use the command (at your own risk and responsibility):
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
In step 22, you evaluate and test the module:
In step 23, uninstalling a module is simple:
In step 24, if you prefer, download code and inspect it before installing, using Save-Module, then browse the module's files in Windows Explorer:
In step 25, after reviewing the code, import the module by locating the .psm1 file which defines the module, using Get-ChildItem, then piping that filename to Import-Module:
In step 26, you uninstall the module from your session and delete the module's folder. You may, of course, wish to keep the module!