diff --git a/src/System.Management.Automation/AssemblyInfo.cs b/src/System.Management.Automation/AssemblyInfo.cs
index 3c03c22e04..559d809fe7 100644
--- a/src/System.Management.Automation/AssemblyInfo.cs
+++ b/src/System.Management.Automation/AssemblyInfo.cs
@@ -14,15 +14,3 @@ using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo(@"System.Management.Automation.Remoting" + @",PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
[assembly: InternalsVisibleTo(@"Microsoft.PowerShell.ConsoleHost" + @",PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
[assembly: InternalsVisibleTo(@"Microsoft.PowerShell.DscSubsystem" + @",PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
-
-namespace System.Management.Automation
-{
- internal static class NTVerpVars
- {
- internal const int PRODUCTMAJORVERSION = 10;
- internal const int PRODUCTMINORVERSION = 0;
- internal const int PRODUCTBUILD = 10032;
- internal const int PRODUCTBUILD_QFE = 0;
- internal const int PACKAGEBUILD_QFE = 814;
- }
-}
diff --git a/src/System.Management.Automation/engine/CommandDiscovery.cs b/src/System.Management.Automation/engine/CommandDiscovery.cs
index 9a126645a7..9ce60e56c0 100644
--- a/src/System.Management.Automation/engine/CommandDiscovery.cs
+++ b/src/System.Management.Automation/engine/CommandDiscovery.cs
@@ -421,7 +421,7 @@ namespace System.Management.Automation
// in single shell mode
if (requiresPSVersion != null)
{
- if (!Utils.IsPSVersionSupported(requiresPSVersion))
+ if (!PSVersionInfo.IsValidPSVersion(requiresPSVersion))
{
ScriptRequiresException scriptRequiresException =
new ScriptRequiresException(
@@ -458,7 +458,7 @@ namespace System.Management.Automation
var message = StringUtil.Format(DiscoveryExceptions.RequiresPSEditionNotCompatible,
scriptInfo.Name,
specifiedEditionsString,
- PSVersionInfo.PSEdition);
+ PSVersionInfo.PSEditionValue);
var ex = new RuntimeException(message);
ex.SetErrorId("ScriptRequiresUnmatchedPSEdition");
ex.SetTargetObject(scriptInfo.Name);
diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs
index 37cd5f19e7..6fa242ce52 100644
--- a/src/System.Management.Automation/engine/InitialSessionState.cs
+++ b/src/System.Management.Automation/engine/InitialSessionState.cs
@@ -3732,7 +3732,7 @@ namespace System.Management.Automation.Runspaces
// implementation and should be refactored.
PSSnapInInfo newPSSnapIn = PSSnapInReader.Read("2", name);
- if (!Utils.IsPSVersionSupported(newPSSnapIn.PSVersion.ToString()))
+ if (!PSVersionInfo.IsValidPSVersion(newPSSnapIn.PSVersion))
{
s_PSSnapInTracer.TraceError("MshSnapin {0} and current monad engine's versions don't match.", name);
diff --git a/src/System.Management.Automation/engine/InternalCommands.cs b/src/System.Management.Automation/engine/InternalCommands.cs
index f1c5f57c88..2afb9c516c 100644
--- a/src/System.Management.Automation/engine/InternalCommands.cs
+++ b/src/System.Management.Automation/engine/InternalCommands.cs
@@ -2654,7 +2654,7 @@ namespace Microsoft.PowerShell.Commands
protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics)
{
Version version = arguments as Version;
- if (version == null || !PSVersionInfo.IsValidPSVersion(version))
+ if (!PSVersionInfo.IsValidPSVersion(version))
{
// No conversion succeeded so throw and exception...
throw new ValidationMetadataException(
diff --git a/src/System.Management.Automation/engine/PSVersionInfo.cs b/src/System.Management.Automation/engine/PSVersionInfo.cs
index 0d292c4852..169024508e 100644
--- a/src/System.Management.Automation/engine/PSVersionInfo.cs
+++ b/src/System.Management.Automation/engine/PSVersionInfo.cs
@@ -58,7 +58,7 @@ namespace System.Management.Automation
private static readonly Version s_psV3Version = new(3, 0);
private static readonly Version s_psV4Version = new(4, 0);
private static readonly Version s_psV5Version = new(5, 0);
- private static readonly Version s_psV51Version = new(5, 1, NTVerpVars.PRODUCTBUILD, NTVerpVars.PRODUCTBUILD_QFE);
+ private static readonly Version s_psV51Version = new(5, 1);
private static readonly Version s_psV6Version = new(6, 0, 0);
private static readonly Version s_psV61Version = new(6, 1, 0);
private static readonly Version s_psV62Version = new(6, 2, 0);
@@ -193,14 +193,6 @@ namespace System.Management.Automation
}
}
- internal static Version[] PSCompatibleVersions
- {
- get
- {
- return (Version[])s_psVersionTable[PSCompatibleVersionsName];
- }
- }
-
///
/// Gets the edition of PowerShell.
///
@@ -208,7 +200,7 @@ namespace System.Management.Automation
{
get
{
- return (string)s_psVersionTable[PSVersionInfo.PSEditionName];
+ return PSEditionValue;
}
}
@@ -220,21 +212,6 @@ namespace System.Management.Automation
}
}
- ///
- ///
- ///
- /// For 2.0 PowerShell, we still use "1" as the registry version key.
- /// For >=3.0 PowerShell, we still use "1" as the registry version key for
- /// Snapin and Custom shell lookup/discovery.
- ///
- internal static string RegistryVersion1Key
- {
- get
- {
- return "1";
- }
- }
-
///
///
///
@@ -270,76 +247,32 @@ namespace System.Management.Automation
return null;
}
- internal static string FeatureVersionString
- {
- get
- {
- return string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}.{1}", PSVersionInfo.PSVersion.Major, PSVersionInfo.PSVersion.Minor);
- }
- }
-
internal static bool IsValidPSVersion(Version version)
{
- if (version.Major == s_psSemVersion.Major)
+ if (version is null)
{
- return version.Minor == s_psSemVersion.Minor;
+ return false;
}
- if (version.Major == s_psV6Version.Major)
+ int minor = version.Minor;
+ switch (version.Major)
{
- return version.Minor == s_psV6Version.Minor;
- }
-
- if (version.Major == s_psV5Version.Major)
- {
- return (version.Minor == s_psV5Version.Minor || version.Minor == s_psV51Version.Minor);
- }
-
- if (version.Major == s_psV4Version.Major)
- {
- return (version.Minor == s_psV4Version.Minor);
- }
- else if (version.Major == s_psV3Version.Major)
- {
- return version.Minor == s_psV3Version.Minor;
- }
- else if (version.Major == s_psV2Version.Major)
- {
- return version.Minor == s_psV2Version.Minor;
- }
- else if (version.Major == s_psV1Version.Major)
- {
- return version.Minor == s_psV1Version.Minor;
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ return minor == 0;
+ case 5:
+ return minor == 0 || minor == 1;
+ case 6:
+ return minor >= 0 && minor <= 2;
+ case 7:
+ return minor >= 0 && minor <= s_psVersion.Minor;
}
return false;
}
- internal static Version PSV4Version
- {
- get { return s_psV4Version; }
- }
-
- internal static Version PSV5Version
- {
- get { return s_psV5Version; }
- }
-
- internal static Version PSV51Version
- {
- get { return s_psV51Version; }
- }
-
- internal static Version PSV6Version
- {
- get { return s_psV6Version; }
- }
-
- internal static Version PSV7Version
- {
- get { return s_psV7Version; }
- }
-
internal static SemanticVersion PSCurrentVersion
{
get { return s_psSemVersion; }
diff --git a/src/System.Management.Automation/engine/Utils.cs b/src/System.Management.Automation/engine/Utils.cs
index 6cb51a4ae8..a3b6b83dc9 100644
--- a/src/System.Management.Automation/engine/Utils.cs
+++ b/src/System.Management.Automation/engine/Utils.cs
@@ -637,41 +637,6 @@ namespace System.Management.Automation
return null;
}
- ///
- /// Checks whether current monad session supports version specified
- /// by ver.
- ///
- /// Version to check.
- /// True if supported, false otherwise.
- internal static bool IsPSVersionSupported(string ver)
- {
- // Convert version to supported format ie., x.x
- Version inputVersion = StringToVersion(ver);
- return IsPSVersionSupported(inputVersion);
- }
-
- ///
- /// Checks whether current monad session supports version specified
- /// by checkVersion.
- ///
- /// Version to check.
- /// True if supported, false otherwise.
- internal static bool IsPSVersionSupported(Version checkVersion)
- {
- if (checkVersion == null)
- {
- return false;
- }
-
- foreach (Version compatibleVersion in PSVersionInfo.PSCompatibleVersions)
- {
- if (checkVersion.Major == compatibleVersion.Major && checkVersion.Minor <= compatibleVersion.Minor)
- return true;
- }
-
- return false;
- }
-
///
/// Checks whether current PowerShell session supports edition specified
/// by checkEdition.
@@ -680,7 +645,7 @@ namespace System.Management.Automation
/// True if supported, false otherwise.
internal static bool IsPSEditionSupported(string checkEdition)
{
- return PSVersionInfo.PSEdition.Equals(checkEdition, StringComparison.OrdinalIgnoreCase);
+ return PSVersionInfo.PSEditionValue.Equals(checkEdition, StringComparison.OrdinalIgnoreCase);
}
///
@@ -690,7 +655,7 @@ namespace System.Management.Automation
/// True if the edition is supported by this runtime, false otherwise.
internal static bool IsPSEditionSupported(IEnumerable editions)
{
- string currentPSEdition = PSVersionInfo.PSEdition;
+ string currentPSEdition = PSVersionInfo.PSEditionValue;
foreach (string edition in editions)
{
if (currentPSEdition.Equals(edition, StringComparison.OrdinalIgnoreCase))
diff --git a/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs b/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs
index ca6d8f7d51..8448007025 100644
--- a/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs
+++ b/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs
@@ -2780,8 +2780,8 @@ namespace System.Management.Automation
{
throw new PSInvalidOperationException(
// The remote session to which you are connected does not support remote debugging.
- // You must connect to a remote computer that is running PowerShell {0} or greater.
- StringUtil.Format(RemotingErrorIdStrings.RemoteDebuggingEndpointVersionError, PSVersionInfo.PSV4Version),
+ // You must connect to a remote computer that is running PowerShell 4.0 or greater.
+ RemotingErrorIdStrings.RemoteDebuggingEndpointVersionError,
null,
"RemoteDebugger:RemoteDebuggingNotSupported",
ErrorCategory.NotImplemented,
diff --git a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteDebuggingCapability.cs b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteDebuggingCapability.cs
index 3162fa3d2b..2c670b1eaa 100644
--- a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteDebuggingCapability.cs
+++ b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteDebuggingCapability.cs
@@ -43,14 +43,14 @@ namespace System.Management.Automation.Remoting
}
// Commands added in v5
- if (PSVersion.Major >= PSVersionInfo.PSV5Version.Major)
+ if (PSVersion.Major >= 5)
{
_supportedCommands.Add(RemoteDebuggingCommands.SetDebuggerStepMode);
_supportedCommands.Add(RemoteDebuggingCommands.SetUnhandledBreakpointMode);
}
// Commands added in v7
- if (PSVersion.Major >= PSVersionInfo.PSV7Version.Major)
+ if (PSVersion.Major >= 7)
{
_supportedCommands.Add(RemoteDebuggingCommands.GetBreakpoint);
_supportedCommands.Add(RemoteDebuggingCommands.SetBreakpoint);
diff --git a/src/System.Management.Automation/engine/remoting/server/ServerRunspacePoolDriver.cs b/src/System.Management.Automation/engine/remoting/server/ServerRunspacePoolDriver.cs
index 11c2d6c4d2..83d0ed0755 100644
--- a/src/System.Management.Automation/engine/remoting/server/ServerRunspacePoolDriver.cs
+++ b/src/System.Management.Automation/engine/remoting/server/ServerRunspacePoolDriver.cs
@@ -472,7 +472,7 @@ namespace System.Management.Automation
// Remote debugger is created only when client version is PSVersion (4.0)
// or greater, and remote session supports debugging.
if ((_driverNestedInvoker != null) &&
- (_clientPSVersion != null && _clientPSVersion >= PSVersionInfo.PSV4Version) &&
+ (_clientPSVersion != null && _clientPSVersion.Major >= 4) &&
(runspace != null && runspace.Debugger != null))
{
_serverRemoteDebugger = new ServerRemoteDebugger(this, runspace, runspace.Debugger);
diff --git a/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx b/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx
index 57d2a22a0a..f65d536f63 100644
--- a/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx
+++ b/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx
@@ -1360,7 +1360,7 @@ All WinRM sessions connected to PowerShell session configurations, such as Micro
The remote session command is currently stopped in the debugger. Use the Enter-PSSession cmdlet to connect interactively to the remote session and automatically enter into the console debugger.
- The remote session to which you are connected does not support remote debugging. You must connect to a remote computer that is running PowerShell {0} or greater.
+ The remote session to which you are connected does not support remote debugging. You must connect to a remote computer that is running PowerShell 4.0 or greater.
Because the session state for session {0}, {1}, {2} is not equal to Open, you cannot run a command in the session. The session state is {3}.