PowerShell

Install-module : The ‘install-module’ command was found in the module ‘PowerShellGet’, but the module could not be loaded.

I've been working last few hours trying to set up my laptop for PowerShell Conference, and one of the tasks is to get my modules up and running. To my surprise on Windows 10 1903 Install-Module thrown a weird error:

PS C:\WINDOWS\system32> install-module
install-module : The ‘install-module' command was found in the module ‘PowerShellGet', but the module could not be
loaded. For more information, run ‘Import-Module PowerShellGet'.
At line:1 char:1
+ install-module
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (install-module:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

The usual fix, without even thinking, Have you tried to turn it off and on again didn't bring any results, so I had to try and fix this the old way by actually doing some simple verifications steps.

What worked for me

It turns out I didn't have to look far and to make sure Execution Policy isn't blocking anything was the right shot.

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\WINDOWS\system32> install-module
install-module : The 'install-module' command was found in the module 'PowerShellGet', but the module could not be
loaded. For more information, run 'Import-Module PowerShellGet'.
At line:1 char:1
+ install-module
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (install-module:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

PS C:\WINDOWS\system32> Set-ExecutionPolicy Unrestricted

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y
PS C:\WINDOWS\system32> Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
PS C:\WINDOWS\system32> install-module                                                                                  
cmdlet Install-Module at command pipeline position 1
Supply values for the following parameters:
Name[0]:
PS C:\WINDOWS\system32>


So a simple command setting execution policy to unrestricted fixed my error. While I was at it, I decided to trust PSGallery so I won't get prompted to confirm the installation of every module out there.

Finally, I was able to install all my usual modules that are about to show up on my session.

This post was last modified on 30 maja, 2019 10:25

Przemyslaw Klys

System Architect with over 14 years of experience in the IT field. Skilled, among others, in Active Directory, Microsoft Exchange and Office 365. Profoundly interested in PowerShell. Software geek.

Share
Published by
Przemyslaw Klys

Recent Posts

Active Directory Replication Summary to your Email or Microsoft Teams

Active Directory replication is a critical process that ensures the consistent and up-to-date state of…

1 tydzień ago

Syncing Global Address List (GAL) to personal contacts and between Office 365 tenants with PowerShell

Hey there! Today, I wanted to introduce you to one of the small but excellent…

5 miesięcy ago

Active Directory Health Check using Microsoft Entra Connect Health Service

Active Directory (AD) is crucial in managing identities and resources within an organization. Ensuring its…

7 miesięcy ago

Seamless HTML Report Creation: Harness the Power of Markdown with PSWriteHTML PowerShell Module

In today's digital age, the ability to create compelling and informative HTML reports and documents…

8 miesięcy ago

How to Efficiently Remove Comments from Your PowerShell Script

As part of my daily development, I create lots of code that I subsequently comment…

8 miesięcy ago

Unlocking PowerShell Magic: Different Approach to Creating ‘Empty’ PSCustomObjects

Today I saw an article from Christian Ritter, "PowerShell: Creating an "empty" PSCustomObject" on X…

9 miesięcy ago