Optimise from powershell 5 scripts to powershell 7

Hi All
I’ve got a lot of powershell scripts that have been written in powershell 5 now with powershell 7 I get quite some errors when trying to connect to Active Directory.
what would be the preferred way to optimise the current scripts so that they continue to work in powershell 7

If they are still working fine with PowerShell 5 why don’t you run them this way? There is actually no reason you have migrate all of your PowerShell scripts to version 7. Version 5 will not disappear in the near future.

Powershell 5 uses full .NET framework, Powershell 7 uses .NET core which is stripped down to allow cross-platform capabilities.

Differences between Windows PowerShell 5.1 and PowerShell 7.x - PowerShell | Microsoft Learn

It appears the ActiveDirectory module is supported in 7, but there are prerequisites:

Active Directory module for PowerShell Core 7. (microsoft.com)
How to install the PowerShell 7 Active Directory module – 4sysops

If you’ve done this and are getting errors, provide the code (formatted for the forum), the error and context around the problem. We cannot see the screen you are looking at provide assistance.

1 Like

If you are working in a production environment, the proprietary modules such as the Active Directory module will likely be best run under PS 5.1 for some time to come.

All the production work I do is still with PS 5.1. It is stable, mature, and the version the modules I need, such as the Active Directory, were originally written for.

When MS releases native, well tested version of the 5.1 modules for PS 7 or newer, I will only then consider them for production. Being cutting edge is fun and educational …when you have time. I don’t. So, I stick with PS 5.1

By all means play and experiment with PS 7 in a lab, but if you support a production Windows network, PS 5.1 is still HIGHLY relevant and current in that context.

1 Like

thanks all for your much appreciated advice

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.