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 May 30, 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

Upgrade Azure Active Directory Connect fails with unexpected error

Today, I made the decision to upgrade my test environment and update the version of…

2 days ago

Mastering Active Directory Hygiene: Automating Stale Computer Cleanup with CleanupMonster

Have you ever looked at your Active Directory and wondered, "Why do I still have…

4 months ago

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…

8 months 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…

1 year 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…

1 year 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…

1 year ago