PowerShell / WindowsCompatibility

Module that allows Windows PowerShell Modules to be used from PSCore6
Other
137 stars 33 forks source link

Problem with DnsServer module and CimSession (de)serialization #37

Closed rmbolger closed 3 years ago

rmbolger commented 6 years ago

First off, thank you all for trying to solve this usability gap while we wait for all of the Win modules we depend on to get ported to Core. Fantastic effort!

I have a module that has a plugin system for interacting with various DNS servers/services. The Windows DNS plugin relies on the DnsServer module that doesn't have a Core compatible version yet. So I figured I'd try to add support for it on Core via this lovely module.

I've got WindowsCompatibility installed and functional which is to say I can run Import-WinModule DnsServer successfully. But I'm running into problems with DnsServer's dependence on CimSession objects.

The plugin code appears to create a New-CimSession against the DNS server successfully. But when I try to run a function and reference the CimSession object, I get the following error.

Cannot process argument transformation on parameter 'CimSession'. Cannot convert the "CimSession: ns.example.com" value of type "Deserialized.Microsoft.Management.Infrastructure.CimSession" to type "Microsoft.Management.Infrastructure.CimSession[]".
At C:\Users\myuser\AppData\Local\Temp\remoteIpMoProxy_DnsServer_2.0.0.0_localhost_754d59ca-b5e1-4372-ba73-762704d969b8\remoteIpMoProxy_DnsServer_2.0.0.0_localhost_754d59ca-b5e1-4372-ba73-762704d969b8.psm1:7297 char:9
+         $steppablePipeline.End()
+         ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidData: (:) [Get-DnsServerZone], ParameterBindin...mationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-DnsServerZone
+ PSComputerName        : localhost

At first, I thought this might be because Core has its own version of CimCmdlets and sending the locally created CimSession object through the implicit remoting connection was screwing things up. So I tried explicitly loading the Windows CimCmdlets module via Import-WinModule as well. But that ended up with a different error when calling New-CimSession.

Cannot bind parameter 'SessionOption'. Cannot convert value "Microsoft.Management.Infrastructure.Options.WSManSessionOptions" to type "Microsoft.Management.Infrastructure.Options.CimSessionOptions". Error: "Cannot convert the "Microsoft.Management.Infrastructure.Options.WSManSessionOptions" value of type "Deserialized.Microsoft.Management.Infrastructure.Options.WSManSessionOptions" to type "Microsoft.Management.Infrastructure.Options.CimSessionOptions"."
+ CategoryInfo          : InvalidArgument: (:) [New-CimSession], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Management.Infrastructure.CimCmdlets.NewCimSessionCommand
+ PSComputerName        : localhost

I'm running this all from Win 10 1803. Here's the output of my Win PS and PS Core $PSVersionTable variables.

Name                           Value
----                           -----
PSVersion                      5.1.17134.48
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.48
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
Name                           Value
----                           -----
PSVersion                      6.0.0
PSEdition                      Core
GitCommitId                    v6.0.0
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
markekraus commented 6 years ago

Hi @rmbolger Do you have some code we can use to reproduce the problem?

rmbolger commented 6 years ago

I just pushed my WIP branch of the module up to Github here. You should be able to just dot source the Windows.ps1 plugin file directly rather than futzing with the rest of the module. I can also try putting together a smaller repro if you'd like.

Here's an example command that works for me from Windows PS, but gets the serialization error from PS Core (since upgraded to 6.0.2). The DNS server in this case is remote and standalone, but using a valid cert for WinRM. Explicit credentials and -WinUseSSL may not be necessary if client and server are in the same AD domain.

Add-DnsTxtWindows 'test.example.com' 'myvalue' 'dns-server.example.com' (Get-Credential) -WinUseSSL
eissko commented 3 years ago

Hello @rmbolger, have u been able to solve this issue please?

P.

rmbolger commented 3 years ago

I never ended up solving it in PowerShell 6. But it seems to have been solved for me in PowerShell 7.