Microsoft 365 Security Blog

How to Move Microsoft 365 Admin Scripts to PowerShell 7.6

Written by Marcus Harris | Nov 20, 2026, 9:00:00 AM

PowerShell 7.4 LTS and PowerShell 7.5 both reached end of support on 10 November 2026, and version 3.10.0 of the Exchange Online module requires PowerShell 7.6.0 or later. A script server that moved off Windows PowerShell 5.1 a couple of years ago is now on an unsupported release, and the next Exchange module update will not run on it.

This guide moves a set of multi-tenant Microsoft 365 admin scripts to PowerShell 7.6 LTS: installing it side by side, finding the 5.1 dependencies across every script and scheduled task, updating modules, comparing output before cutover, and switching the tasks over. Windows PowerShell 5.1 stays installed throughout, so nothing breaks while the work is in progress.

Applies to

  • Admin workstations and script servers that run reporting, baseline or provisioning scripts against client tenants.
  • Scripts using the Microsoft Graph PowerShell SDK, the ExchangeOnlineManagement module or other Microsoft 365 modules.
  • Scheduled tasks and Azure Automation runbooks that currently start Windows PowerShell 5.1 or PowerShell 7.4 or 7.5.

Scripts that run on client devices, such as Intune platform and remediation scripts, are out of scope. They run as SYSTEM, which Microsoft lists as a known gap for the PowerShell 7 MSIX package, and Windows PowerShell 5.1 remains supported on current Windows versions for that work.

What changed and when

Change Date Effect on admin scripts
PowerShell 7.4 LTS and 7.5 end of support 10 November 2026 No further fixes. Moving from 7.4 to 7.5 does not extend support.
ExchangeOnlineManagement 3.10.0 June 2026 Requires PowerShell 7.6.0 or later in PowerShell 7, because of .NET 10 dependencies. All versions still work in Windows PowerShell 5.1.
Microsoft Graph PowerShell SDK v3 Q4 2026 Supported on PowerShell 7 only. Version 2 enters a 12-month retirement period on Windows PowerShell 5.x with security fixes only.
PowerShell 7 included in Windows Next Windows release Installed alongside Windows PowerShell 5.1, not in place of it. Earlier Windows versions keep 5.1 as before.
PowerShell 7.6 LTS Supported to 14 November 2028 The target release for anything that runs unattended.
7.6 is the only PowerShell 7 release that is both supported today and able to load the current Exchange Online module.

How the migration runs

The first four steps change nothing in production, so they can be done during normal working hours.

Step 1: Install PowerShell 7.6 LTS side by side

PowerShell 7 installs to its own folder, runs as pwsh.exe and keeps its own module path and profile. Windows PowerShell 5.1 is untouched.

Item Windows PowerShell 5.1 PowerShell 7
Executable powershell.exe pwsh.exe
Install folder $Env:windir\System32\WindowsPowerShell\v1.0 $Env:ProgramFiles\PowerShell\7
All users modules $Env:ProgramFiles\WindowsPowerShell\Modules $Env:ProgramFiles\PowerShell\Modules
Profile folder $HOME\Documents\WindowsPowerShell $HOME\Documents\PowerShell

On script servers, install 7.6 from the MSI. Microsoft continues to ship the MSI for 7.6 through its lifecycle, while 7.7 and later move to MSIX, and MSIX does not yet cover execution by system-level services such as Task Scheduler. Confirm the version from a new pwsh session:

$PSVersionTable.PSVersion
$PSVersionTable.PSEdition   # Core for PowerShell 7, Desktop for 5.1

Step 2: Inventory scripts and scheduled tasks

Scan every script folder for the commands and modules that do not exist in PowerShell 7. The patterns below cover the removals that turn up most often in Microsoft 365 admin scripts.

$ScriptRoot = 'D:\Scripts'

$Checks = [ordered]@{
    'Get-WmiObject|Invoke-WmiMethod|Set-WmiInstance' = 'WMI v1 cmdlets removed. Use the CIM cmdlets.'
    'Get-EventLog|Write-EventLog|New-EventLog'       = 'EventLog cmdlets removed. Use Get-WinEvent.'
    '^\s*workflow\s'                                 = 'Workflows are not supported.'
    'Add-PSSnapin'                                   = 'Snap-ins are not supported.'
    'ConvertFrom-String|New-WebServiceProxy'         = 'Cmdlet removed.'
    'MSOnline|Connect-MsolService'                   = 'Retired module. Rewrite with Microsoft Graph.'
    'Import-Module\s+AzureAD|Connect-AzureAD'        = 'Retired module. Rewrite with Microsoft Graph.'
}

$Findings = foreach ($File in Get-ChildItem $ScriptRoot -Recurse -Include *.ps1, *.psm1) {
    foreach ($Pattern in $Checks.Keys) {
        Select-String -Path $File.FullName -Pattern $Pattern | ForEach-Object {
            [pscustomobject]@{
                Script = $File.FullName
                Line   = $_.LineNumber
                Match  = $_.Line.Trim()
                Action = $Checks[$Pattern]
            }
        }
    }
}

$Findings | Export-Csv .\ps7-findings.csv -Encoding utf8

Then list the scheduled tasks that start Windows PowerShell, so each one can be tied to a script in the findings file:

Get-ScheduledTask |
    Where-Object { $_.Actions.Execute -match 'powershell(\.exe)?$' } |
    Select-Object TaskPath, TaskName,
        @{ n = 'RunAs';     e = { $_.Principal.UserId } },
        @{ n = 'Arguments'; e = { $_.Actions.Arguments -join ' ' } } |
    Export-Csv .\ps-tasks.csv -Encoding utf8

Treat Azure Automation runbooks on the 5.1 runtime the same way: export the runbook content and run it through the same scan.

Step 3: Classify each script

Every script ends up in one of five groups. Record the group against each row in the findings file before changing anything.

Finding Action
No findings, uses Graph or Exchange Online cmdlets only Move as is, then compare output in step 5.
Removed cmdlet Rewrite the affected lines, for example Get-WmiObject to Get-CimInstance.
MSOnline or AzureAD module Rewrite with the Microsoft Graph PowerShell SDK. These modules are retired in every edition.
A module that will not load in PowerShell 7 Load it with Import-Module -UseWindowsPowerShell as an interim bridge and log it for replacement.
Runs on client devices as SYSTEM Leave on Windows PowerShell 5.1.

-UseWindowsPowerShell creates a proxy module in PowerShell 7 that runs the module's cmdlets in a local Windows PowerShell process. Objects come back serialised, so test any script that pipes those results into methods rather than properties.

Step 4: Update modules in the PowerShell 7 scope

Modules installed under Windows PowerShell are not in the PowerShell 7 all users path. Install them again from an elevated pwsh session, and keep the PowerShellGet module present, as the Exchange Online module needs it for REST connections on Windows.

Install-Module ExchangeOnlineManagement, Microsoft.Graph.Authentication -Scope AllUsers

Get-Module -ListAvailable ExchangeOnlineManagement, Microsoft.Graph.Authentication |
    Select-Object Name, Version, ModuleBase

Add a requirements block to the top of each migrated script so it fails fast, with a clear message, if it is ever started in the wrong edition or against an old module:

#Requires -Version 7.6
#Requires -Modules @{ ModuleName = 'ExchangeOnlineManagement'; ModuleVersion = '3.10.0' }

Pin module versions on unattended hosts and update them deliberately. When Graph PowerShell SDK v3 is released, test it against a single tenant before it reaches the scheduled jobs. Microsoft states the aim is for existing cmdlet usage to work unchanged, with any intentional differences documented.

Step 5: Compare output from both editions

Run each script in both editions against the same test tenant and compare the results. The example below assumes a reporting script that takes a tenant and an output path as parameters. Reporting scripts are the easiest to verify this way, and they make up most multi-tenant automation.

$Script = 'D:\Scripts\Get-MailboxReport.ps1'
$Tenant = 'contoso-test.onmicrosoft.com'

& powershell.exe -NoProfile -File $Script -TenantId $Tenant -OutFile .\out-51.csv
& pwsh.exe       -NoProfile -File $Script -TenantId $Tenant -OutFile .\out-76.csv

Compare-Object (Import-Csv .\out-51.csv) (Import-Csv .\out-76.csv) -Property UserPrincipalName, ItemCount

No output from Compare-Object means the rows match on the properties you named. Set -Encoding explicitly on any file a script writes, so both editions produce identical files and downstream imports do not change.

Step 6: Cut over scheduled tasks and runbooks

Change each task's action to start pwsh.exe, keeping the arguments as they were. Do one task, let it run on schedule, check its output, then do the rest.

$Task = Get-ScheduledTask -TaskName 'Tenant-Mailbox-Report'
$Task.Actions[0].Execute = "$Env:ProgramFiles\PowerShell\7\pwsh.exe"
Set-ScheduledTask -InputObject $Task

For Azure Automation, move each runbook to a PowerShell 7 runtime environment, import the same pinned modules into it, and run it once manually before relinking the schedule.

Keep the old 5.1 versions of the scripts for one full reporting cycle. After that, remove the 5.1 scheduled task entries so there is only one copy of each job.

Troubleshooting

Symptom Cause Fix
ExchangeOnlineManagement fails to load in PowerShell 7. Module 3.10.0 or later on PowerShell 7.4 or 7.5. Install PowerShell 7.6 LTS, per step 1.
"The term 'Get-WmiObject' is not recognized". WMI v1 cmdlets were removed from PowerShell 7. Use Get-CimInstance and the other CIM cmdlets.
Module is installed but pwsh cannot find it. It was installed into the Windows PowerShell module path. Install it again from pwsh, per step 4.
Exchange Online REST connection fails on Windows. The PowerShellGet module is missing. Install PowerShellGet in the PowerShell 7 scope.
Script works interactively, fails from Task Scheduler. PowerShell 7 installed as MSIX, which does not yet support system-level services. Use the 7.6 MSI on script servers.
Functions or variables from your profile are missing. PowerShell 7 reads its profile from $HOME\Documents\PowerShell. Copy the profile across, or better, move anything a scheduled script needs into the script itself.
Security & Compliance cmdlets unavailable on a Mac or Linux host. Connect-IPPSSession is not available in PowerShell 7 on those platforms. Run those scripts from a Windows host.

Once the findings file is empty and every task points at pwsh.exe, the estate is on a release supported until November 2028, and Graph SDK v3 becomes a routine module update.