Windows PowerShell and PowerShell 7 compatibility
Microsoft's edit ·
Microsoft's commit message in MicrosoftDocs/PowerShell-Docs · commit f60b3a4 · +73 −3 lines · also on GitHub
11
---
2
−ms.date: 06/28/2023
2
+ms.date: 04/02/2024
33
title: Differences between Windows PowerShell 5.1 and PowerShell 7.x
44
description: This article summarizes the differences and breaking changes from Windows PowerShell 5.1 and the current version of PowerShell that is based on .NET Core.
55
---
⋯ 16 unchanged lines
2222
PowerShell. For a detailed discussion of changes between versions and the addition of new features,
2323
see the **What's New** articles for each version.
2424
25
+- [What's new in PowerShell 7.5][36]
2526
- [What's new in PowerShell 7.4][35]
2627
- [What's new in PowerShell 7.3][34]
2728
- [What's new in PowerShell 7.2][33]
⋯ 7 unchanged lines
3536
Microsoft Windows. This is significant because PowerShell provides direct access to the underlying
3637
framework types and methods. As a result, scripts that run on Windows may not run on non-Windows
3738
platforms because of the differences in the frameworks. For more information about changes in .NET
38
−Core, see
39
−[Breaking changes for migration from .NET Framework to .NET Core][03].
39
+Core, see [Breaking changes for migration from .NET Framework to .NET Core][03].
4040
4141
Each new release of PowerShell is built on a newer version of .NET. There can be breaking changes in
4242
.NET that affect PowerShell.
4343
44
+- PowerShell 7.5 - Built on .NET 9.0
4445
- PowerShell 7.4 - Built on .NET 8.0
4546
- PowerShell 7.3 - Built on .NET 7.0
4647
- PowerShell 7.2 (LTS-current) - Built on .NET 6.0 (LTS-current)
⋯ 13 unchanged lines
6061
- [about_Windows_PowerShell_Compatibility][09]
6162
- [PowerShell 7 module compatibility][29]
6263
64
+### Be aware of .NET method changes
65
+
66
+While .NET method changes are not specific to PowerShell, they can affect your scripts, especially
67
+if you are calling .NET methods directly. Also, there might be new overloads for constructors. This
68
+can have an impact on how you create objects using `New-Object` or the `[type]::new()` method.
69
+
70
+For example, .NET added overloads to the `[System.String]::Split()` method that aren't available in
71
+.NET Framework 4.5. The following list shows the overloads for the `Split()` method available in
72
+Windows PowerShell 5.1:
73
+
74
+```powershell
75
+PS> "".Split
76
+
77
+OverloadDefinitions
78
+-------------------
79
+string[] Split(Params char[] separator)
80
+string[] Split(char[] separator, int count)
81
+string[] Split(char[] separator, System.StringSplitOptions options)
82
+string[] Split(char[] separator, int count, System.StringSplitOptions options)
83
+string[] Split(string[] separator, System.StringSplitOptions options)
84
+string[] Split(string[] separator, int count, System.StringSplitOptions options)
85
+```
86
+
87
+The following list shows the overloads for the `Split()` method available in PowerShell 7:
88
+
89
+```powershell
90
+"".Split
91
+
92
+OverloadDefinitions
93
+-------------------
94
+string[] Split(char separator, System.StringSplitOptions options)
95
+string[] Split(char separator, int count, System.StringSplitOptions options)
96
+string[] Split(Params char[] separator)
97
+string[] Split(char[] separator, int count)
98
+string[] Split(char[] separator, System.StringSplitOptions options)
99
+string[] Split(char[] separator, int count, System.StringSplitOptions options)
100
+string[] Split(string separator, System.StringSplitOptions options)
101
+string[] Split(string separator, int count, System.StringSplitOptions options)
102
+string[] Split(string[] separator, System.StringSplitOptions options)
103
+string[] Split(string[] separator, int count, System.StringSplitOptions options)
104
+```
105
+
106
+In Windows PowerShell 5.1, you could pass a character array (`char[]`) to the `Split()` method as a
107
+`string`. The method splits the target string at any occurrence of a character in the array. The
108
+following command splits the target string in Windows PowerShell 5.1, but not in PowerShell 7:
109
+
110
+```powershell
111
+# PowerShell 7 example
112
+"1111p2222q3333".Split('pq')
113
+```
114
+
115
+```Output
116
+1111p2222q3333
117
+```
118
+
119
+To bind to the correct overload, you must typecast the string to a character array:
120
+
121
+```powershell
122
+# PowerShell 7 example
123
+"1111p2222q3333".Split([char[]]'pq')
124
+```
125
+
126
+```Output
127
+1111
128
+2222
129
+3333
130
+```
131
+
63132
## Modules no longer shipped with PowerShell
64133
65134
For various compatibility reasons, the following modules are no longer included in PowerShell.
⋯ 1116 unchanged lines
11821251
[33]: What-s-New-in-PowerShell-72.md
11831252
[34]: What-s-New-in-PowerShell-73.md
11841253
[35]: What-s-New-in-PowerShell-74.md
1254
+[36]: What-s-New-in-PowerShell-75.md
Microsoft's Markdown source from MicrosoftDocs/PowerShell-Docs, © Microsoft Corporation, under CC BY 4.0. Changed lines with up to 3 unchanged lines around each; ChangeIntel kept this copy 10 Oct 03:16 UTC. The commit date is when the source changed, which can be hours or days before Learn published it.