Fix Install-module Error in PowerShell

Hi Everyone this is Prem, I have worked as Microsoft 365 support ambassador. In this blog I will share how to Fix Install-module Error in PowerShell when trying to connect PowerShell to Office 365 Services.

 

This issue can occur when we are trying to connect to the powershell to office 365 services like Exchange online, Microsoft admin center, etc and we try to Install the respective module.

 

When we run the Install-Module command it gives us the error The ‘Install-Module’ command was found in the module ‘PowerShellGet’, but the module could not be loaded. For more information, run ‘Import-Module PowerShellGet’

 

Let se How we can Fix Install-module Error in PowerShell:

When connecting with PowerShell to any Office 365 service make sure the PowerShell is ran as an Administrator.

 

Search for windows PowerShell on your computer and run it as an administrator:

 Fix Install-module Error in PowerShell

Once opened it should look like this:

 Fix Install-module Error in PowerShell

 

And Now if I try to run the command to install exchange online module command then it might give me the following error:

 

Fix Install-module Error in PowerShell

 

To fix this we will have to check by Execution policy set on the computer, I can check the same by running the following command:

 

Get-ExecutionPolicy

The output of the above command will look something like this:

 

Fix Install-module Error in PowerShell

 

For my computer it is set to Restricted, Now I can allow it for everyone to be able to install modules who are using the computer or just myself by running the below command respectively:

 

To allow everyone using the computer be able to run Install-module commands without the error run the following command:

Set-ExecutionPolicy RemoteSigned

Fix Install-module Error in PowerShell

After you run the above command you will be prompted to confirm the changes, you can type A as shown above or Y. This will set the policy and you should then be able to run the Install-Module command respectively.

 

If you get error: Set-ExecutionPolicy : Windows PowerShell updated your execution policy successfully, but the setting is overridden by a policy defined at a more specific scope. Run the below command which is of smaller scope.

 

To allow only your account using the computer be able to run Install-module commands run the following command:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Fix Install-module Error in PowerShell

After you run the above command you will be prompted to confirm the changes, you can type A as shown above or Y. This will set the policy and you should then be able to run the script.

 

Setting the execution policy as RemoteSigned allow it to run the script or files which are signed by trusted publisher.

 

After running the above command successfully you should be able to install the module which you want.

 

If you are looking to connect the PowerShell with specific office 365 services you can refer the below article respectively:

 

How to connect to Exchange Online using PowerShell in Office 365 or How to Connect to Microsoft 365 Admin Center using PowerShell or How to Connect to SharePoint Online using PowerShell

 

Date:26/02/2023

Author: Prem

Tag: Fix Install-module Error in PowerShell

Leave a Comment

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