Skip to content

How to Install Microsoft PowerShell PSResourceGet module

PSResourceGet is a module with commands for discovering, installing, updating, and publishing PowerShell artifacts like Modules, DSC Resources, Role Capabilities, and Scripts. The PSResourceGet is the latest package manager and replaces the PowerShellGet v2 module. In this article, you will learn how to install Microsoft PowerShell PSResourceGet module.

Microsoft PowerShell PSResourceGet

The PSResourceGet is the module that provides the ability to install, update, and locate modules and scripts in repositories like the PowerShell Gallery.

The PSResourceGet is the new package manager for PowerShell. It replaces the PowerShellGet v2 module. Now you might ask why it hasn’t become v3? It was, in the initial phase of the project. Eventually it was decided to change the name during many breaking changes. You will find v3 in the PowerShell gallery as compatibility module.

Windows PowerShell 5.1 comes with version 1.0.0.1 of PowerShellGet preinstalled. This version of PowerShellGet has limited features and doesn’t support the updated capabilities of the PowerShell Gallery. To install PSResourceGet, you must first update to the latest version of PowerShellGet.

Install Microsoft PowerShell PSResourceGet module

To install Microsoft PowerShell PSResourceGet module on your system, follow the steps below.

1. Set Windows PowerShell Execution Policy

By default, we can’t install scripts. To require all PowerShell scripts that you download from the internet are signed by a trusted publisher, run PowerShell as administrator, and run the cmdlet.

Set-ExecutionPolicy RemoteSigned -Force

Important: Close and re-open the elevated Windows PowerShell window to have the changes apply.

2. Install PowerShellGet module

Run PowerShell as administrator. Run the command Install-Module PowershellGet -Force. When asked to install NuGet provider, press Y and follow with Enter.

Install-Module PowershellGet -Force

If you get an error that it’s unable to install, read the article Unable to install NuGet provider for PowerShell.

3. Install Microsoft PowerShell PSResourceGet module

Install the Microsoft PowerShell PSResourceGet module.

Install-Module -Name Microsoft.PowerShell.PSResourceGet -Force

After you have installed Microsoft PowerShell PSResourceGet, you should open a new PowerShell session. PowerShell automatically loads the newest version of the module when you use a PowerShell cmdlet.

We also recommend that you register the PowerShell Gallery as a trusted repository. This will not prompt you to trust the reposority every time when you want to download a module.

Set-PSResourceRepository -Name PSGallery -Trusted

Get PSResourceGet module version

Verify that the PSResourceGet module is installed.

Get-PSResource Microsoft.PowerShell.PSResourceGet -Scope AllUsers | ft -AutoSize

The below PowerShell output appears.

Version Name                               Repository Description
------- ----                               ---------- -----------
1.0.2   Microsoft.PowerShell.PSResourceGet PSGallery  PowerShell module with commands for discovering, installing, updating and publishing the PowerShell artifacts like Modules, Scripts, and DSC Resources.

Find PSResourceGet module latest available version

Find-Module Microsoft.PowerShell.PSResourceGet | ft -AutoSize

The below output appears.

Version Name                               Repository Description
------- ----                               ---------- -----------
1.0.2   Microsoft.PowerShell.PSResourceGet PSGallery  PowerShell module with commands for discovering, installing, updating and publishing the PowerShell artifacts like Modules, Scripts, and DSC Resources.

Microsoft PowerShell PSResourceGet cmdlets

See the below list of all the cmdlets.

PSResourceGet cmdletDescription
Find-PSResourceSearches for packages from a repository (local or remote), based on a name or other package properties.
Get-InstalledPSResourceReturns modules and scripts installed on the machine via PowerShellGet.
Get-PSResourceRepositoryFinds and returns registered repository information.
Get-PSScriptFileInfoReturns the metadata for a script.
Import-PSGetRepositoryFinds the repositories registered with PowerShellGet and registers them for PSResourceGet.
Install-PSResourceInstalls resources from a registered repository.
New-PSScriptFileInfoThe cmdlet creates a new script file, including metadata about the script.
Publish-PSResourcePublishes a specified module from the local computer to PSResource repository.
Register-PSResourceRepositoryRegisters a repository for PowerShell resources.
Save-PSResourceSaves resources (modules and scripts) from a registered repository onto the machine.
Set-PSResourceRepositorySets information for a registered repository.
Test-PSScriptFileInfoTests the comment-based metadata in a .ps1 file to ensure it’s valid for publication.
Uninstall-PSResourceUninstalls a resource that was installed using PowerShellGet.
Unregister-PSResourceRepositoryRemoves a registered repository from the local machine.
Update-PSModuleManifestUpdates a module manifest file.
Update-PSResourceDownloads and installs the newest version of a package already installed on the local machine.
Update-PSScriptFileInfoThis cmdlet updates the comment-based metadata in an existing script .ps1 file.

How to use Microsoft PowerShell PSResourceGet

Let’s have a look at how to install modules with PSResourceGet.

Install-PSResource

In our example, we like to install both modules:

  1. Microsoft Graph PowerShell module
  2. Microsoft Graph Beta PowerShell module

We don’t have to add the -TrustReposority parameter to the commands below because we already added PSGallery to the trusted repository in the previous install steps. But you might overlooked it, so let’s add it.

Note: Use the -Reinstall parameter in the command to install the latest version of a module even if the latest version is already installed. The installed version is overwritten. This allows you to repair a damaged installation of the module. If an older version of the module is installed, the new version is installed side-by-side in a new version-specific folder.

Install-PSResource Microsoft.Graph -Reinstall -Scope AllUsers -TrustRepository
Install-PSResource Microsoft.Graph.Beta -Reinstall -Scope AllUsers -TrustRepository

If you like to install a specific module version, use the -Version parameter.

Install-PSResource Microsoft.Graph -Version 2.14.0 -Scope AllUsers -TrustRepository
Install-PSResource Microsoft.Graph.Beta -Version 2.14.0 -Scope AllUsers -TrustRepository

Get-InstalledPSResource

Check which modules are installed on the machine.

Get-InstalledPSResource -Scope AllUsers

Filter the installed modules.

Get-InstalledPSResource Microsoft.Graph* -Scope AllUsers | Where-Object { $_.Name -notlike "Microsoft.Graph.Beta*" }
Get-InstalledPSResource Microsoft.Graph* -Scope AllUsers | Where-Object { $_.Name -like "Microsoft.Graph.Beta*" }

Let’s get the location path where the modules are installed.

Note: When you run the Install-PSResource cmdlet to install a module, it can be installed in a different location when running it from Windows PowerShell 5.1 or PowerShell 7.

Get-InstalledPSResource -Scope AllUsers | ft Name, InstalledLocation

The folder paths below are the default places where the module installations are installed. You can open the below folders in File Explorer.

Windows PowerShell 5.1 for current user:

%USERPROFILE%\Documents\WindowsPowerShell\Modules

Windows PowerShell 5.1 for all users:

C:\Program Files\WindowsPowerShell\Modules

PowerShell 7 for current user:

%USERPROFILE%\Documents\PowerShell\Modules

PowerShell 7 for all users:

C:\Program Files\PowerShell\Modules

Uninstall-PSResource

If we like to uninstall a module with PSResourceGet, we need to use the Uninstall-PSResource cmdlet.

This will remove all Microsoft Graph modules.

Get-InstalledPSResource Microsoft.Graph* -Scope AllUsers | Uninstall-PSResource -Scope AllUsers -SkipDependencyCheck

You can always filter and remove the modules you don’t want.

Get-InstalledPSResource Microsoft.Graph* -Scope AllUsers | Where-Object { $_.Name -notlike "Microsoft.Graph.Beta*" } | Uninstall-PSResource -Scope AllUsers -SkipDependencyCheck
Get-InstalledPSResource Microsoft.Graph* -Scope AllUsers | Where-Object { $_.Name -like "Microsoft.Graph.Beta*" } | Uninstall-PSResource -Scope AllUsers -SkipDependencyCheck

PSResourceGet vs. PowerShellGet v2

Let’s compare PSResourceGet and PowerShellGet v2 to see which one is faster at installing and removing modules.

In this example, we will use the Measure-Command cmdlet to install and uninstall the Microsoft Graph PowerShell module. It’s an excellent test because it has 39 modules.

PSResourceGet is much faster compared to PowerShellGet v2.

CmdletsPSRecourceGet (version 1.0.2)PowerShellGet v2 (version 2.2.5)
Install-PSResource58 seconds
Uninstall-PSResource396 milliseconds
Install-Module3 minutes and 14 seconds
Uninstall-Module3 minutes and 48 seconds

That’s it!

Read more: How to Install and Update PowerShell 7 »

Conclusion

You learned how to install Microsoft PowerShell PSResourceGet module. Run Windows PowerShell 5.1 or PowerShell 7 and run the commands step by step to install the latest PSResourceGet module. From now on, use PSResourceGet to install, update, and remove modules.

Did you enjoy this article? You may also like Connect to Exchange Online PowerShell. Don’t forget to follow us and share this article.

ALI TAJRAN

ALI TAJRAN

ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Read more »

This Post Has 0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *