diff --git a/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs b/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs
index 19c093e368..76601ff6df 100644
--- a/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs
+++ b/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs
@@ -2320,13 +2320,8 @@ else
set
{
- RemotingCommandUtil.CheckPSVersion(value);
-
- // Check if specified version of PowerShell is installed
- RemotingCommandUtil.CheckIfPowerShellVersionIsInstalled(value);
-
- psVersion = value;
- isPSVersionSpecified = true;
+ // PowerShell 7 remoting endpoints do not support PSVersion.
+ throw new PSNotSupportedException(RemotingErrorIdStrings.PowerShellVersionNotSupported);
}
}
diff --git a/src/System.Management.Automation/engine/remoting/commands/StartJob.cs b/src/System.Management.Automation/engine/remoting/commands/StartJob.cs
index 90e10bb8f4..ff7b844d7f 100644
--- a/src/System.Management.Automation/engine/remoting/commands/StartJob.cs
+++ b/src/System.Management.Automation/engine/remoting/commands/StartJob.cs
@@ -512,10 +512,12 @@ namespace Microsoft.PowerShell.Commands
set
{
- RemotingCommandUtil.CheckPSVersion(value);
-
- // Check if specified version of PowerShell is installed
- RemotingCommandUtil.CheckIfPowerShellVersionIsInstalled(value);
+ // PSVersion value can only be 5.1 for Start-Job.
+ if (!(value.Major == 5 && value.Minor == 1))
+ {
+ throw new ArgumentException(
+ StringUtil.Format(RemotingErrorIdStrings.PSVersionParameterOutOfRange, value, "PSVersion"));
+ }
_psVersion = value;
}
diff --git a/src/System.Management.Automation/engine/remoting/commands/remotingcommandutil.cs b/src/System.Management.Automation/engine/remoting/commands/remotingcommandutil.cs
index 094dcedc6a..f30e4ba510 100644
--- a/src/System.Management.Automation/engine/remoting/commands/remotingcommandutil.cs
+++ b/src/System.Management.Automation/engine/remoting/commands/remotingcommandutil.cs
@@ -165,60 +165,5 @@ namespace Microsoft.PowerShell.Commands
throw new InvalidOperationException(errorRecord.ToString());
}
}
-
- internal static void CheckPSVersion(Version version)
- {
- // PSVersion value can only be 2.0, 3.0, 4.0, 5.0, or 5.1
- if (version != null)
- {
- // PSVersion value can only be 2.0, 3.0, 4.0, 5.0, or 5.1
- if (!(version.Major >= 2 && version.Major <= 4 && version.Minor == 0) &&
- !(version.Major == 5 && version.Minor <= 1))
- {
- throw new ArgumentException(
- StringUtil.Format(RemotingErrorIdStrings.PSVersionParameterOutOfRange, version, "PSVersion"));
- }
- }
- }
-
- ///
- /// Checks if the specified version of PowerShell is installed.
- ///
- ///
- internal static void CheckIfPowerShellVersionIsInstalled(Version version)
- {
- // Check if PowerShell 2.0 is installed
- if (version != null && version.Major == 2)
- {
-#if CORECLR
- // PowerShell 2.0 is not available for CoreCLR
- throw new ArgumentException(
- PSRemotingErrorInvariants.FormatResourceString(
- RemotingErrorIdStrings.PowerShellNotInstalled,
- version, "PSVersion"));
-#else
- // Because of app-compat issues, in Win8, we will have PS 2.0 installed by default but not .NET 2.0
- // In such a case, it is not enough if we check just PowerShell registry keys. We also need to check if .NET 2.0 is installed.
- try
- {
- RegistryKey engineKey = PSSnapInReader.GetPSEngineKey(PSVersionInfo.RegistryVersion1Key);
- // Also check for .NET 2.0 installation
- if (!PsUtils.FrameworkRegistryInstallation.IsFrameworkInstalled(2, 0, 0))
- {
- throw new ArgumentException(
- PSRemotingErrorInvariants.FormatResourceString(
- RemotingErrorIdStrings.NetFrameWorkV2NotInstalled));
- }
- }
- catch (PSArgumentException)
- {
- throw new ArgumentException(
- PSRemotingErrorInvariants.FormatResourceString(
- RemotingErrorIdStrings.PowerShellNotInstalled,
- version, "PSVersion"));
- }
-#endif
- }
- }
}
}
diff --git a/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx b/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx
index 441228c9c4..680e6d1a6b 100644
--- a/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx
+++ b/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx
@@ -837,8 +837,7 @@ Note that 'Start-Job' is not supported by design in scenarios where PowerShell i
A {1} job source adapter threw an exception with the following message: {0}
- The value {0} is not valid for the {1} parameter. The available values are 2.0, 3.0, 4.0, 5.0, 5.1.
- {StrContains="2.0"} {StrContains="3.0"}
+ The value {0} is not valid for the {1} parameter. The only allowed value is 5.1.
The Wait and Keep parameters cannot be used together in the same command.
@@ -846,8 +845,8 @@ Note that 'Start-Job' is not supported by design in scenarios where PowerShell i
The WriteEvents parameter cannot be used without the Wait parameter.
-
- PowerShell {0} is not installed. Install PowerShell {0}, and then try again.
+
+ PowerShell remoting endpoint versioning is not supported on PowerShell Core.
The following type cannot be instantiated because its constructor is not public: {0}.
diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Job.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Job.Tests.ps1
index 06d84230dc..90477267b4 100644
--- a/test/powershell/Modules/Microsoft.PowerShell.Core/Job.Tests.ps1
+++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Job.Tests.ps1
@@ -243,3 +243,16 @@ Describe "Ampersand background test" -Tag "CI","Slow" {
}
}
}
+
+Describe "Start-Job with -PSVersion parameter" -Tag "CI" {
+
+ It "Verifies that -PSVersion is not supported except for version 5.1" {
+ { Start-Job -PSVersion 2.0 } | Should -Throw -ErrorId 'ParameterBindingFailed,Microsoft.PowerShell.Commands.StartJobCommand'
+ }
+
+ It "Verifies that -PSVersion 5.1 runs the job in a version 5.1 PowerShell session" -Skip:(-not $IsWindows) {
+ $version = Start-Job -PSVersion 5.1 -ScriptBlock { $PSVersionTable } | Receive-Job -Wait -AutoRemoveJob
+ $version.PSVersion.Major | Should -Be 5
+ $version.PSVersion.Minor | Should -Be 1
+ }
+}
diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/PSSessionConfiguration.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/PSSessionConfiguration.Tests.ps1
index d910f2c265..a4e9e1e511 100644
--- a/test/powershell/Modules/Microsoft.PowerShell.Core/PSSessionConfiguration.Tests.ps1
+++ b/test/powershell/Modules/Microsoft.PowerShell.Core/PSSessionConfiguration.Tests.ps1
@@ -491,13 +491,9 @@ namespace PowershellTestConfigNamespace
$Result.Session.UseSharedProcess | Should -Be $UseSharedProcess
}
- It "Validate Register-PSSessionConfiguration -PSVersion" {
+ It "Verifies that Register-PSSessionConfiguration -PSVersion parameter is not supported" {
- Register-PSSessionConfiguration -Name $TestSessionConfigName -PSVersion 5.1
- $Session = Get-PSSessionConfiguration -Name $TestSessionConfigName
-
- $Session.Name | Should -Be $TestSessionConfigName
- $Session.PSVersion | Should -BeExactly 5.1
+ { Register-PSSessionConfiguration -Name $TestSessionConfigName -PSVersion 5.1 } | Should -Throw -ErrorId 'ParameterBindingFailed,Microsoft.PowerShell.Commands.RegisterPSSessionConfigurationCommand'
}
It "Validate Register-PSSessionConfiguration -startupscript parameter" -Pending {
@@ -567,13 +563,9 @@ namespace PowershellTestConfigNamespace
$Result.Session.UseSharedProcess | Should -Be $UseSharedProcess
}
- It "Validate Set-PSSessionConfiguration -PSVersion" {
+ It "Verifies that Set-PSSessionConfiguration -PSVersion parameter is not supported" {
- Set-PSSessionConfiguration -Name $TestSessionConfigName -PSVersion 5.1
- $Session = (Get-PSSessionConfiguration -Name $TestSessionConfigName)
-
- $Session.Name | Should -Be $TestSessionConfigName
- $Session.PSVersion | Should -BeExactly 5.1
+ { Set-PSSessionConfiguration -Name $TestSessionConfigName -PSVersion 5.1 } | Should -Throw -ErrorId 'ParameterBindingFailed,Microsoft.PowerShell.Commands.SetPSSessionConfigurationCommand'
}
It "Validate Set-PSSessionConfiguration -startupscript parameter" -Pending {