Skip to content

Update all Microsoft Cloud PowerShell modules

directorcia edited this page Nov 16, 2025 · 7 revisions

Update all Microsoft Cloud PowerShell modules (o365-update.ps1)

This guide explains how to use the o365-update.ps1 script to install, update, and clean up Microsoft Cloud PowerShell modules (Graph, Exchange Online, Teams, SharePoint, Az, and more). It reflects the latest script changes (v2.10) with PowerShell 7-only support and an improved elevation experience.


Requirements

  • PowerShell 7.0 or higher (PS5 is not supported)
  • Administrator privileges (system-wide module management uses AllUsers scope)
  • Internet connectivity to PowerShell Gallery and Microsoft endpoints
  • Sufficient disk space (2+ GB recommended for large modules like Az/Graph)

You can check your version with:

$PSVersionTable.PSVersion

Quick Start

  1. Open PowerShell 7 as Administrator (Start Menu → search "PowerShell 7" → right‑click → Run as administrator).
  2. Run the script from the repo folder:
.\o365-update.ps1

If you started in a non-admin session, the script prints a friendly message and a ready‑to‑copy elevation command. You can paste and run it to relaunch elevated:

Start-Process -Verb RunAs pwsh -ArgumentList @('-NoProfile','-ExecutionPolicy','Bypass','-File', 'C:\Downloads\source\Office365\o365-update.ps1')

Replace the path with your script’s full path if different.


What the script does

  • Installs or updates Microsoft Cloud modules: Microsoft.Graph (+ Authentication), ExchangeOnlineManagement, MicrosoftTeams, PnP.PowerShell, Az, SharePoint Online Admin, WinGet client, etc.
  • Removes deprecated modules automatically (AzureAD, AzureADPreview, MSOnline, AIPService, aadrm, SharePointPnPPowerShellOnline, WindowsAutoPilotIntune, O365CentralizedAddInDeployment, MSCommerce).
  • Optimizes downloads (TLS 1.2, higher connection limits) and shows progress with time estimates.
  • Handles core module updates (PowerShellGet, PackageManagement) using conflict‑free, side‑by‑side installs.
  • Optionally cleans up old module versions automatically to prevent multi‑version conflicts.
  • Provides connectivity checks and clear troubleshooting guidance.

Parameters

  • -Prompt: Ask before installing or cleaning up; interactive prompts for multi‑version cleanup.
  • -CreateLog: Start transcript logging (path printed at start). Use -LogPath to specify directory.
  • -LogPath <dir>: Target folder for transcript logs when -CreateLog is used.
  • -SkipDeprecatedCleanup: Skip removal of deprecated modules.
  • -SkipVersionCleanup: Skip automatic cleanup of old versions after updates.
  • -CheckOnly: Report current/online versions without installing/updating.
  • -CheckSessions: Only check for PowerShell session conflicts and exit.
  • -TerminateConflicts: Automatically close conflicting PowerShell sessions (when supported).
  • -ModuleScope <All|Graph|Azure|Exchange|Teams|SharePoint|PowerApps>: Limit which module categories are processed.
  • -SkipConnectivityCheck: Skip network connectivity tests.
  • -Repository <name>: Target repository (default: PSGallery).

Common scenarios

  • Update everything, no prompts:
.\o365-update.ps1
  • Review actions interactively, preserve multiple versions:
.\o365-update.ps1 -Prompt -SkipVersionCleanup
  • Only check versions, don’t change anything:
.\o365-update.ps1 -CheckOnly
  • Target just Graph + Exchange:
.\o365-update.ps1 -ModuleScope Graph,Exchange
  • Create a log file in a specific folder:
.\o365-update.ps1 -CreateLog -LogPath 'C:\Logs'

Module categories and included modules

  • Graph: Microsoft.Graph, Microsoft.Graph.Authentication
  • Exchange: ExchangeOnlineManagement
  • Teams: MicrosoftTeams
  • SharePoint: PnP.PowerShell, Microsoft.Online.SharePoint.PowerShell
  • Azure: Az
  • PowerApps: Microsoft.PowerApps.PowerShell, Microsoft.PowerApps.Administration.PowerShell
  • Core: PowerShellGet, PackageManagement
  • Other: Microsoft.WinGet.Client

Deprecated modules automatically removed

  • AzureAD, AzureADPreview, MSOnline, AIPService, aadrm, SharePointPnPPowerShellOnline, WindowsAutoPilotIntune, O365CentralizedAddInDeployment, MSCommerce

Progress, estimates, and large modules

Large modules (e.g., Az, Microsoft.Graph) include more detailed progress and time estimates. In restricted environments, verification phases can appear to “hang” — this is normal; do not cancel. The script prints clear phase information and reminders.


Automatic cleanup of old versions

By default, after a successful install/update the script removes older versions to avoid conflicts. Use -SkipVersionCleanup to keep multiple versions, or run interactive cleanup with -Prompt. There is also a comprehensive cleanup option at the end when using -Prompt.


Connectivity checks

The script can test connectivity to:

  • PowerShell Gallery (www.powershellgallery.com)
  • Microsoft Download Center (download.microsoft.com)
  • NuGet.org (api.nuget.org)

Failures won’t necessarily block updates, but they can slow or break operations. You can skip these checks using -SkipConnectivityCheck.


Troubleshooting

  • Not running as Administrator
    • The script will instruct you to relaunch elevated and shows a copy‑ready command.
  • PowerShell 5.x errors
    • The script requires PS 7+. Install PowerShell 7 and rerun.
  • Core module "currently in use" messages (PowerShellGet/PackageManagement)
    • The script safely installs the newer version side‑by‑side and advises restarting PowerShell to use it.
  • Command conflicts (AllowClobber)
    • The script detects conflicts and retries with -AllowClobber when possible.
  • Slow installs for Az/Graph
    • Normal for large modules; verification can take minutes. Ensure stable connectivity and disk space.
  • Corporate environments (policy/WDAC/AppLocker)
    • Execution policy and language mode restrictions may slow or block some optimizations. Run elevated PS7 and consult your administrator if needed.

Why PowerShell 7 only?

  • Modern modules and tooling are optimized for PowerShell 7.
  • PS 7 provides improved performance, compatibility, and error handling.
  • Avoids parser differences and limitations in Windows PowerShell 5.1.

Install PowerShell 7:


Changelog (highlights)

v2.10 (November 2025)

  • Enforced PowerShell 7+ support (#Requires -Version 7.0).
  • Replaced #Requires -RunAsAdministrator with a friendly, actionable elevation check.
  • Printed a safe, copyable elevation command using array‑form -ArgumentList.
  • Tightened prerequisite checks to require PS 7+.
  • Improved non‑admin experience with clear steps and rationale.

v2.9

  • Automatic cleanup of old module versions after updates.
  • Interactive cleanup prompts with -Prompt and end‑of‑run comprehensive cleanup.
  • Added Remove-OldModuleVersions and Remove-AllOldModuleVersions helpers.

v2.8

  • Consolidated session conflict detection/handling and removed duplicate prompts.
  • Fixed compatibility by removing ?? (null coalescing) for older hosts.

v2.7

  • Eliminated noisy “PackageManagement is currently in use” warnings.
  • Comprehensive suppression of output streams during core module updates.

(See inline script comments for prior versions.)


Verification and next steps

  • After updates, restart PowerShell to pick up new core module versions.
  • Verify installations:
Get-Module -ListAvailable PowerShellGet,PackageManagement,Microsoft.Graph,ExchangeOnlineManagement,MicrosoftTeams,PnP.PowerShell,Az | Select Name,Version | Sort Name
  • Review logs if -CreateLog was used (path printed at start).

Links


Additional links (related tools and docs)

Clone this wiki locally