Skip to content

Import-PSSession fails with ParameterBindingException if it is running with PowerShell 5.1 #4195

@ryhayash

Description

@ryhayash

Steps to reproduce

[Server Side (PowerShell 5.1)]
New-PSSessionConfigurationFile -Path .\TestSession.pssc -SessionType RestrictedRemoteServer -LanguageMode NoLanguage
Register-PSSessionConfiguration -Name TestSession -Path .\TestSession.pssc
Restart-Service WinRM

[Client Side (PowerShell 5.1)]
$credential = Get-Credential
$session = New-PSSession -ComputerName ServerName -Credential $credential -ConfigurationName TestSession
Import-PSSession $session <--- This will fail.

This doesn't happen if client is PowerShell 5.0 or lower version.

=================================================================

[Debug note]
I took iDNA trace for wsmprovhost.exe on server side and here is the error path. 

This happens if client powershell is 5.1 or above as a parameter ‘PowerShellVersion’ is added to argument for Get-FormatData wchich is called internally in the Import-PSSession. Then, "Get-FormatData -TypeName xx -PowerShellVersion 5.1" is performed in wsmprovhost.exe on server side. But, 'PowerShellVersion' is marked as unbound parameter in the RestrictedRemoteServer session. Then, ParameterBindingException is thrown from VerifyArgumentsProcessed().

0:005> sxe clr
0:005> g
:
(a04.8dc): CLR exception - code e0434352 (first/second chance not available)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
Time Travel Position: 3F0A400000001
ntdll!RtlRaiseException:
00007ff8`d4dea110 4055 push rbp

0:021> !pe
Exception object: 000001cc1c0bdf00
Exception type: System.Management.Automation.ParameterBindingException
Message:
InnerException:
StackTrace (generated):

StackTraceString:
HResult: 80131501

0:021> !mk
ESP RetAddr
00:U 0000009567abd758 00007ff8d4dea110 ntdll!RtlRaiseException
01:U 0000009567abd760 00007ff8d1cf7788 kernelbase!RaiseException+0x68
02:U 0000009567abd840 00007ff8b937047a clr!RaiseTheExceptionInternalOnly+0x2aa
03:U 0000009567abd940 00007ff8b93705ea clr!IL_Throw+0x10b
04:M 0000009567abdaf0 00007ff8b4252363 System.Management.Automation.CmdletParameterBinderController.VerifyArgumentsProcessed(System.Management.Automation.ParameterBindingException)(+0x121 IL)(+0x0 Native)
05:M 0000009567abdbb0 00007ff8b424ec8d System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(System.Collections.ObjectModel.Collection1<System.Management.Automation.CommandParameterInternal>)(+0x15b IL)(+0x0 Native) 06:M 0000009567abdc50 00007ff8b424e6aa System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(System.Collections.ObjectModel.Collection1<System.Management.Automation.CommandParameterInternal>)(+0x1a IL)(+0x69 Native)
07:M 0000009567abdcd0 00007ff8b424e464 System.Management.Automation.CommandProcessor.BindCommandLineParameters()(+0x38 IL)(+0x14d Native)
08:M 0000009567abdd30 00007ff8b424c94a System.Management.Automation.CommandProcessorBase.DoPrepare(System.Collections.IDictionary)(+0x1e IL)(+0x43 Native)
:

Expected behavior

You can use imported the following commands.

・Clear-Host (cls, clear)
・Exit-PSSession (exsn, exit)
・Get-Command (gcm)
・Get-FormatData
・Get-Help
・Measure-Object (measure)
・Out-Default
・Select-Object (select)

Actual behavior

Receive the following error when running Import-PSSession.

Import-PSSession : Running the Get-Command command in a remote session reported the following error: A parameter cannot be found that matches parameter name 'PowerShellVersion'.

Environment data

This issue occurs only with PowerShell 5.1.

Metadata

Metadata

Assignees

Labels

Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-RemotingPSRP issues with any transport layer

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions