PowerShell v5 to v7.1 Migration

Update: Below issue corrected after reinstalling Exchange Online Management v2.0.4-Preview. I suspect there was some corruption during the initial install. Thank you.

Hello.

We’re in a hybrid Exchange/O365 environment managed in great part by PowerShell scripts.

I am trying to migrate scripts from 5.0 to 7.1. I’ve installed PS v7.1 x64 and Exchange Online Management v2.0.4-Preview6.

Connect-ExchangeOnline -UserPrincipalName globalAdmin@contoso.com -ShowProgress $true
Set-Mailbox -Identity email-one@contoso.com -GrantSendOnBehalfTo email-two@contoso.com
Disconnect-ExchangeOnline -Confirm:$false
The above runs in v5 with the following message:

Creating a new Remote PowerShell session using Modern Authentication for implicit remoting of “Set-Mailbox” command …

When the same script is run on v7.1 it fails with the following error:

Set-Mailbox: Recipient “email-one” couldn’t be read from domain controller “xxxxxxxxxxxxxxxx.PROD.OUTLOOK.COM”. This may be due to replication delays. Switching out of Forest mode should allow this operation to complete successfully.

Seems like it’s failing to connect to Azure AD. But why v5 connects and not 7.1 ?

Thanks.

For flexibility and to support the needs of IT, DevOps engineers, and developers, there are several options available to install PowerShell 7. In most cases, the installation options can be reduced to the following methods:

Deploy PowerShell using the MSI package
Deploy PowerShell using the ZIP package

Deploying the MSI package requires Administrator permission. The ZIP package can be deployed by any user. The ZIP package is the easiest way to install PowerShell 7 for testing, before committing to a full installation.

Using PowerShell 7 side-by-side with Windows PowerShell 5.1
PowerShell 7 is designed to coexist with Windows PowerShell 5.1. The following features ensure that your investment in PowerShell is protected and your migration to PowerShell 7 is simple.

Separate installation path and executable name
Separate PSModulePath
Separate profiles for each version
Improved module compatibility
New remoting endpoints
Group policy support
Separate Event logs
Separate installation path and executable name
PowerShell 7 installs to a new directory, enabling side-by-side execution with Windows PowerShell 5.1.

Install locations by version:

Windows PowerShell 5.1: $env:WINDIR\System32\WindowsPowerShell\v1.0
PowerShell Core 6.x: $env:ProgramFiles\PowerShell\6
PowerShell 7: $env:ProgramFiles\PowerShell\7
The new location is added to your PATH allowing you to run both Windows PowerShell 5.1 and PowerShell 7. If you’re migrating from PowerShell Core 6.x to PowerShell 7, PowerShell 6 is removed and the PATH replaced.

In Windows PowerShell, the PowerShell executable is named powershell.exe. In version 6 and above, the executable is named pwsh.exe. The new name makes it easy to support side-by-side execution of both versions.

I hope this information will be helpful to migrate Powershell version 5 to 7.1

Ben Martin