Fix PowerShell Install-Module MSOnline, error:No match was found for the specified search criteria and module name 'MSOnline'

 

Today I was trying to run some office 365 commands but I couldn’t install MSonline modules:

PS C:\WINDOWS\system32> Install-Module -Name MSOnline
PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'MSOnline'.
Try Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Ex
   ception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

Checking the repository:

Get-PSRepository

WARNING: Unable to find module repositories.

The simple fix was reset the repository:

Register-PSRepository -Default

Than check the repository:

PS C:\WINDOWS\system32> Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Untrusted            https://www.powershellgallery.com/api/v2

All look good :)

I can coninue now to instal MSonline

PS C:\WINDOWS\system32> Install-Module MSOnline

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): 

Business as usual from now, connect to microsoft, bring informations about licence:

PS C:\WINDOWS\system32> Connect-MsolService
PS C:\WINDOWS\system32> Get-MsolAccountSku