# Optimise from powershell 5 scripts to powershell 7

**URL:** <https://forums.powershell.org/t/optimise-from-powershell-5-scripts-to-powershell-7/21843>\
**Category:** PowerShell Help\
**Created:** [March 9, 2023, 5:16am UTC](https://forums.powershell.org/t/optimise-from-powershell-5-scripts-to-powershell-7/21843 "2023-03-09T05:16:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![acer4605](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@acer4605](https://forums.powershell.org/u/acer4605)\
**Post date:** [March 9, 2023, 5:16am UTC](https://forums.powershell.org/t/optimise-from-powershell-5-scripts-to-powershell-7/21843/1 "2023-03-09T05:16:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [March 9, 2023, 7:43am UTC](https://forums.powershell.org/t/optimise-from-powershell-5-scripts-to-powershell-7/21843/2 "2023-03-09T07:43:17Z")

</div>

> [@acer4605](#):
>
> with powershell 7 I get quite some errors when trying to connect to Active Directory.

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.

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [March 9, 2023, 3:50pm UTC](https://forums.powershell.org/t/optimise-from-powershell-5-scripts-to-powershell-7/21843/3 "2023-03-09T15:50:45Z")

</div>

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](https://learn.microsoft.com/en-us/powershell/scripting/whats-new/differences-from-windows-powershell?view=powershell-7.3)

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

[Active Directory module for PowerShell Core 7. (microsoft.com)](https://social.technet.microsoft.com/Forums/en-US/840c061b-c9a0-494d-ac0c-0e2db7dd6417/active-directory-module-for-powershell-core-7)  
[How to install the PowerShell 7 Active Directory module – 4sysops](https://4sysops.com/archives/how-to-install-the-powershell-7-active-directory-module/)

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.

---

<div class="post-metadata">

**Author:** ![Matt](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@Matt](https://forums.powershell.org/u/Matt)\
**Post date:** [March 11, 2023, 2:27am UTC](https://forums.powershell.org/t/optimise-from-powershell-5-scripts-to-powershell-7/21843/4 "2023-03-11T02:27:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![acer4605](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@acer4605](https://forums.powershell.org/u/acer4605)\
**Post date:** [March 17, 2023, 6:34am UTC](https://forums.powershell.org/t/optimise-from-powershell-5-scripts-to-powershell-7/21843/5 "2023-03-17T06:34:40Z")

</div>

thanks all for your much appreciated advice

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [February 10, 2024, 5:34pm UTC](https://forums.powershell.org/t/optimise-from-powershell-5-scripts-to-powershell-7/21843/6 "2024-02-10T17:34:04Z")

</div>

Closed on February 10, 2024, 5:34pm UTC

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