Using SharePoint Online Management Shell with PowerShell 7

To start using SharePoint Online Management shell, you just need to install the module or import it if you already had it installed, and then start enjoying it.

Install-Module -Name Microsoft.Online.SharePoint.PowerShell

It works perfectly in PowerShell 5 but failed miserably in PowerShell 7. It throws an error when trying to connect to SharePoint Online.

The workaround is to use import the module in a compatible mode.

Import-Module Microsoft.Online.SharePoint.PowerShell -UseWindowsPowerShell

But if you only have PowerShell 7 or install the module in PowerShell 7, you won’t be able to import the module in the compatible mode, because no valid module file was found in any module directory.l

You will have to specify the location of the module file to import it. By default, you should be able to locate the installed module from the following location.


Then run the following cmdlet and you should be all set.

import-Module "%userprofile%\Documents\PowerShell\Modules\Microsoft.Online.SharePoint.PowerShell.0.23710.12000\Microsoft.Online.SharePoint.PowerShell.psd1" -UseWindowsPowerShell

Leave a Reply

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