Latest Posts

Common issues with PowerShell while installing modules like MSONLINE, AzureAD | PowerShell Install-Module:The term ‘Install-Module’ is not recognized

No comments:
You want to connect to Microsoft 365 tenant with PowerShell to do some bulk operations like assigning licenses to users in bulk, change user properties, or just a simple password reset. You are about to begin your magic by installing your first PowerShell module and face this error  - not a good start, Duh!

PowerShell Install-Module:The term ‘Install-Module’ is not recognized as the name of a cmdlet, function, script file,or operable program.

Check the spelling of the name, or if a path was included,verify that the path is correct and try again.
At line:1 char :1
+Install-module msonline



You try to force the Install-Module cmdlet with -Force switch but meet another error. 😔

Install-Module MSONLINE -Force




What's missing? Why can't you install the PowerShell module?

Most likely, at least one out of below four is missing on your computer - 
  1. PowerShell Version
  2. TLS 1.2
  3. NuGet Provider Package
  4. PSGallery Repository 
Lets see them one by one. 

1. PowerShell Version

To install the powershell modules using install-module cmdlet, you need to run PowerShell 5.1 or higher. 

You can check the current version by simply typing HOST in the PowerShell console:

Get-Host



If the above cmdlet returns version lower than 5.1, you must install Windows Management Framework 5.1

To solve this - you can download it from Microsoft site here


2. TLS 1.2

Without TLS 1.2, you can't successfully Install NuGet Package Provider which is a prerequisite for installing new PowerShell Modules on a system.

You can check if your PowerShell has support for TLS 1.2 by running:


If you don't see the 'TLS12' in the list, you can enable it for the current PowerShell Session or permanently.

Enable TLS 1.2 in current session only - 

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12


Enable TLS 1.2 permanently- 

# Open Powershell (As Admin)
# Run the following cmdlets to set .NET Framework strong cryptography registry keys:

# Set strong cryptography on 64 bit .Net Framework (version 4 and above)
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord

# Set strong cryptography on 32 bit .Net Framework (version 4 and above)
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord

Exit

# Open PowerShell again and check the current available TLS versions

[Net.ServicePointManager]::SecurityProtocol

Bonus: 

How can you spot the issue is TLS without running these cmdlets?
By looking at the error, which reads - 

PackageManagement\Install-PackageProvider : No match was found for the specified search criteria for the provider ‘NuGet’. The package provider requires ‘PackageManagement’ and ‘Provider’ tags. Please
check if the specified package has the tags.

3. NuGet Package Provider

Install-PackageProvider cmdlet installs modules available the PowerShell Gallery with the PackageManagement tag. PackageManagement requires to download the NuGet package provider. 

You can check if NuGet is already available on your machine by running:

Get-PackageProvider


If NuGet package provider is not installed, install it by running below cmdlet in an elevated PowerShell window:

Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force

4. PSGallery Repository

If the error is due to incorrectly installed or not installed PSRepository, the error may look like:
The error can also look slightly different i.e.

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

To solve this Run the Get-PSRepository cmdlet to confirm the PSGallery PSRepository is installed on the system. 
The output should look like below: 

Get-PSRepository

If not, Restore the default repository by using the command

Register-PSRepository -Default

Bonus: 

How can you spot the issue is PSRepository without running these cmdlets?
By looking at the error, which reads - 

PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'MSOnline'.

The problem is now solved! You can install PowerShell Modules now!

Install-Module MSONLINE -AllowClobber -Force


Enjoy!
Read More

Connect-MsolService : Exception of type 'Microsoft.Online.Administration.Automation.MicrosoftOnlineException' was thrown | 0x800488EE

No comments:
You are trying to use Windows PowerShell to connect to the Microsoft Online Services like Microsoft 365, Azure, or Microsoft Intune. You've downloaded and installed the required Module using the relevant Install-Module cmdlet, and are just ready to connect to the service via PowerShell. 

But you find yourself with this unfamiliar, weird  looking Error! 😣

Connect-MsolService : Exception of type
'Microsoft.Online.Administration.Automation.MicrosoftOnlineException' was thrown.

At line:1 char:1
+ Connect-MsolService
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [Connect-MsolService], Mic
rosoftOnlineException
+ FullyQualifiedErrorId : 0x800488EE,Microsoft.Online.Administration.Automation.ConnectMsolService


You try to resolve the error by usual troubleshooting practices like below yet the server does not connect correctly. 😠

  • Reboot the server
  • Upgrade to the latest version for PowerShell
  • Re-install PowerShell module
  • Check a machine supports TLS 1.2

What else to to? I troubleshooted this myself successfully spending 45+ minutes myself quite recently when helping someone configure MFA for VPN Clients using NPS Server Extension. I found out this error 0x800488EE is indeed connected to the Sign-in-Assistant service. Yes, its been more than a decade since Microsoft launched this tiny little tool which used to be a 'must have' even for client machines to connect using Outlook and Lync (yes, this old). 

You need to Uninstall and Re-install Microsoft Online Services Sign-In Assistant for IT Professionals RTW from below links. It comes in two variants, if the regular one does not work, you can install the beta version 

Now, the connection works fine!  ðŸ˜Š

If the PowerShell still does not connect, try to Restart the Online Services Sign-In Assistant service. To do this, follow these steps:

  • Open Control Panel, click Administrative Tools, and then click Services.
  • In the list of services, right-click Microsoft Online Services Sign-In Assistant, and then click Restart.


Read More