Summary
It’s a good practice to ensure the latest version of the SharePoint Online Module is installed, because it’s constantly being updated with new and improved features.
I’m just sharing a quick PowerShell script that ensures the latest SharePoint online PowerShell module is installed.
There 2 different ways to install this module.
- Download and install using Windows installer from https://go.microsoft.com/fwlink/p/?LinkId=255251
- Install from the PowerShell Gallery “Install-Module -Name Microsoft.Online.SharePoint.PowerShell“
If you don’t know what version or which method was used to install the SharePoint Online PowerShell module, this script is for you.
The Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# This script will uninstall the Microsoft.Online.SharePoint.PowerShell" from Windows and PowerShell. # If the PowerShell version was installed it will be reinstalled. # If the MSI version was installed it will be reinstalled. # If no versions were installed, the PowerShell version will be installed. # Uninstall SPO if installed from Windows then install with PowerShell $spomod = Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ListAvailable | Select Name,Version if ($spomod) { # Uninstall Operation Get-Module -Name 'Microsoft.Online.SharePoint.PowerShell' -ListAvailable | Select Name,Version | Uninstall-Module -Force -AllVersions # Install SPO PowerShell Install-Module -Name 'Microsoft.Online.SharePoint.PowerShell' -Force -SkipPublisherCheck Write-Host "Close and reopen PowerShell, so the changes take effect" -ForegroundColor Green break } # Uninstall SPO if installed from Windows then install with PowerShell $spoapp = Get-WmiObject -Class Win32_Product | where-Object {$_.name -Match "SharePoint Online Management Shell"} if ($spoapp) { # Uninstall Operation $spoapp.Uninstall() # Install SPO PowerShell Install-Module -Name 'Microsoft.Online.SharePoint.PowerShell' -Force -SkipPublisherCheck Write-Host "Close and reopen PowerShell, so the changes take effect" -ForegroundColor Green break } #if the SPO Module is not installed by MSI or PS, install it with PS if ($null -eq $spoapp -or $spomod) { Install-Module -Name 'Microsoft.Online.SharePoint.PowerShell' -Force -SkipPublisherCheck Write-Host "Close and reopen PowerShell, so the changes take effect" -ForegroundColor Green} |
What does the script do?
- If the Windows installer version is installed, uninstall it.
- If the PowerShell Gallery version is installed, uninstall it.
- Install the latest version SharePoint Online Module from the PowerShell Gallery.
More Information
The following sites are a great starting point to learn more about the SharePoint Online PowerShell module.
Intro to SharePoint Online Management Shell | Microsoft Learn
Get started with the SharePoint Online Management Shell | Microsoft Learn
Microsoft.Online.SharePoint.PowerShell Module | Microsoft Learn