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.
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.