Ironman Software Forums
Continue the conversion on the Ironman Software forums. Chat with over 1000 users about PowerShell, PowerShell Universal, and PowerShell Pro Tools.
In this post, we’ll look at the newest version of PowerShellGet.
PowerShellGet is the module that provides the ability to install, update, and locate modules and scripts in repositories like the PowerShell Gallery. The previous version of this module includes cmdlets like Install-Module
, Find-Module
and Save-Module
.
PowerShellGet v3 is a completely rewritten implementation of the module. It provides more generic PSResource
cmdlets rather than Install-Module
or Save-Script
. The new version is intended to improve the maintainability of the codebase which in turn should help address issues with the previous version of the module. The PowerShell team would love feedback on this module.
You can install PowerShellGet v3 from the PowerShell Gallery. First, make sure that you have the latest stable version of PowerShellGet and PackageManagement.
Install-Module PowerShellGet -Force -AllowClobber
Next, install the preview version of PowerShellGet. In this blog post, we’ll be using v3.0.12-beta.
Install-Module PowerShellGet -Force -AllowPrerelease
The cmdlet names have changed in PowerShellGet v3. Instead of Install-Module
, you will use Install-PSResource
. It’s actually the same cmdlet for all resources such as scripts and DSC resources.
Install-PSResource -Name Universal
The Install-PSResource
cmdlet supports similar parameters to Install-Module
but have slightly different names and meanings.
For example, -AllowClobber
was optional in Install-Module
but is now the default for Install-PSResource
. You can use -NoClobber
to change this behavior.
Install-PSResource -Name dbatools -Version '1.1.41' -NoClobber
The -Scope
parameter can be used to install the module for CurrentUser
or AllUsers
. CurrentUser
is the default setting. You will need to be running as administrator to install to all users.
Install-PSResource -Name 'PSWindowsUpdate' -Scope AllUsers
You can also install DSC resources with Install-PSResource
. The syntax is very much the same as with modules.
Install-PSResource -Name 'NetworkingDsc'
Much like Save-Module
, you can use Save-PSResource
to download a module for deployment to offline machines or to save into your own repository. Save-PSResource
supports parameters like -AsNupkg
and -IncludeXml
to change what is downloaded. NuPkg files are special ZIP files that contain manifest information and are used with the NuGet package management system.
Save-PSResource -Name Universal -AsNupkg -Path .\universal.nupkg
You can use Get-PSResource
to list modules, and other resources, that have been installed with PowerShellGet.
Get-PSResource
You can use the Uninstall-PSResource
cmdlet to uninstall a module.
Uninstall-PSResource -Name Universal
You can publish modules, an other resources, to repositories using Publish-PSResource
.
Publish-PSResource -Path .\universal -ApiKey 'Test'
By default, you will have the PowerShell Gallery defined as a repository. It will not be trusted but you can use the -TrustRepository
cmdlet on the *-PSResource
cmdlets to avoid the prompt to trust the repository.
Install-PSResource -Name 'PendingReboot' -TrustRepository
You can trust a repository by using the Set-PSResourceRepository
cmdlet. You won’t be prompted to trust the repository with each call from now on.
Set-PSResourceRepository -Name PSGallery -Trusted
You can register a repository by using the Register-PSResourceRepository
cmdlet.
Register-PSResourceRepository -Name Local -URL \\server\share
To reverse the change, use Unregister-PSResourceRepository
.
Unregister-PSResourceRepository -Name Local
To find resources with PowerShellGet, you’ll use the Find-PSResource
cmdlet.
Find-PSResource -Name Universal
You can specify the -Type
parameter to look for resources by type.
Find-PSResource -Name PSDscResources -Type DscResource
You can use the -Tag
parameter to look up resources with tags.
Find-PSResource -Tag universal-dashboard
You can also use wildcard searches to find resources that contain a pattern.
Find-PSResource -Name Universal*
Since PowerShellGet v2 and v3 are very different, the PowerShell team has released a compatibility module so that you can continue to use the original syntax and commands.
You’ll need to install the CompatPowerShellGet
module in order to use the previous commands with the new version of PowerShellGet.
Install-PSResource -Name CompatPowerShellGet
Now, you can use cmdlets like Install-Module
and it will map the command to Install-PSResource
automatically.
Install-Module -Name dbatools -AllowPrerelease
Internally, this executes the following.
Install-PSResource -Name dbatools -Prerelease
The command will work as expected but you will see a warning.
Install-Module -Name dbatools -AllowPrerelease
WARNING: The cmdlet 'Install-Module' is deprecated, please use 'Install-PSResource'.
PowerShellGet v3 is the next major version of the package management cmdlets for PowerShell. At the time of this article, the module is still in prerelease and you should consider providing feedback to the PowerShell team.
Find this useful? Please consider sharing this article. Have a question about PowerShell? Contact us and we'll write a post about it.
Continue the conversion on the Ironman Software forums. Chat with over 1000 users about PowerShell, PowerShell Universal, and PowerShell Pro Tools.
Receive once-a-month updates about Ironman Software. You'll learn about our product updates and blogs related to PowerShell.