PowerShellGet 3.0
PowerShellGet 2 (for example, PowerShellGet 2.2.4.1) implements the Install-Module, Update-Module, and Save-Module module commands demonstrated at the beginning of this chapter.
PowerShellGet 3.0 is in preview at the time of writing; the following commands are based on the beta7 pre-release. One of the key features is that this new version does not depend on the PackageManagement module, allowing a simpler installation process, avoiding the need to bootstrap the NuGet provider, making upgrading the module simpler.
The preview version also uses new command names, completely divorcing it from the previous implementations of PowerShellGet. The change in command names means the new version can safely be installed alongside any existing version.
PowerShellGet 3.0 can be installed as follows:
Install-Module PowerShellGet -Force -AllowPrerelease
Once installed, you'll need to register the PowerShell Gallery or another repository:
Register-PSResourceRepository -PSGallery
In PowerShellGet 2.0, you implement separate commands to work with modules and scripts. PowerShellGet 3.0 does not differentiate between modules and scripts; all artifacts are termed PSResource, and all searches use the Find-PSResource command. For example, we can find a module by using the following command:
Find-PSResource -Name Indented.Net.IP -Type Module
The Type parameter may be omitted without affecting the search results in this case.
Most of the commands in PowerShellGet 3.0 use the same approach as those in PowerShellGet 2.2.4 and below. Over time, the differences between the commands are likely to start to appear; for example, Install-PSResource includes a Reinstall parameter, which is somewhat like the Force parameter for Install-Module in PowerShellGet 2.
Repositories
Like older versions of PowerShellGet, repositories are registered on a per-user basis. In PowerShellGet 2.2.4 and below, the repository configuration file is found in the following path:
$env:LOCALAPPDATA\Microsoft\Windows\PowerShell\PowerShellGet\PSRepositories.xml
The PSRepositories.xml file is stored in CliXml format and may be read using the Import-CliXml command. The file is normally read and updated using Get-PSRepository, Register-PSRepository, and Unregister-PSRespository.
PowerShellGet 3.0 uses a simpler format for the PSResourceRespository.xml file. The file may be found in the following path:
$env:LOCALAPPDATA\PowerShellGet\PSResourceRepository.xml
The Get-PSResourceRepository, Register-PSResourceRepository, and Unregister-PSResourceRepository commands are the expected way of interacting with this file.
As with older versions of PowerShellGet, storing credentials for a repository is not currently supported. If a repository requires authentication, the Credential parameter must be used explicitly with each operation.
Version ranges
Find-PSResource allows wildcards to be used for the Version parameter; using * will return all available versions except pre-release. The Prerelease parameter may be added to include those:
Find-PSResource -Name PowerShellGet -Version *
A range of versions may be defined using the range syntax used by NuGet, which is described in the following document:
https://docs.microsoft.com/nuget/concepts/package-versioning#version-ranges-and-wildcards
For example, the highest version of PowerShellGet available between 1.0 (inclusive) and 2.0 (exclusive) may be found using this:
Find-PSResource -Name PowerShellGet -Version '[1.0,2.0)'
The search can be changed to be inclusive by changing the closing ) to ]. For example, the following command will find version 2.0.0 of PowerShellGet:
Find-PSResource -Name PowerShellGet -Version '[1.0,2.0]'
The same syntax will be available when declaring dependencies between modules.