Prerequisites
Steps to reproduce
I am trying to open a remote WMI session in a powershell script I'm running from a .Net project (using System.Management.Automation.Powershell)
When running the script in powershell command line, or running the .net project directly from the visual studio the script works, however when publishing the .net project and running the published version it fails.
I receive the error while attempting to bind a parameter to the New-CimSession cmdlet generated by the New-CimSessionOption cmdlet. The New-CimSessionOption generates an object of type DComSessionOptions which is inherits the expected CimSessionOptions however it seems that it got deserialized (lost fidelity) and therefore the parameter failed to bind.
I have made several attempts to fix this using casting as well as create the dcom options my self and pass it explicitly as DComSessionOptions. In all cases attempting to run New-CimSession fails on the same error.
`
$SessionOption = New-CimSessionOption -Culture $Script:InvariantCulture -UICulture $Script:InvariantCulture -Protocol DCOM
$sessionParameters = @{
ComputerName = $ComputerAddress
SessionOption = $DcomOptions
Credential = $credentials
}
# Create session
$session = New-CimSession @sessionParameters -ErrorAction SilentlyContinue`
Published using:
dotnet publish C:\repos\WMI\WMITester\WMITester.csproj -c Release -r win7-x64 -o .\publish\WMITester\win\Release\x64 /p:PublishSingleFile=True /p:IncludeNativeLibrariesForSelfExtract=true /p:IncludeAllContentForSelfExtract=true /p:SelfContained=true /p:BuildNumber=8
Expected behavior
$session has a valid CimSession
(it happens this way in some modes of running the script)
Actual behavior
$session is null error detailed bellow.
Error details
Cannot bind parameter 'SessionOption'. Cannot convert value "Microsoft.Management.Infrastructure.Options.DComSessionOptions" to type "Microsoft.Management.Infrastructure.Options.CimSessionOptions". Error: "Cannot convert the "Microsoft.Management.Infrastructure.Options.DComSessionOptions" value of type "Deserialized.Microsoft.Management.Infrastructure.Options.DComSessionOptions" to type "Microsoft.Management.Infrastructure.Options.CimSessionOptions"
Environment data
$PSVersionTable.PSVersion 7.1.3
.Net 5.0
Visuals
No response
Prerequisites
Steps to reproduce
I am trying to open a remote WMI session in a powershell script I'm running from a .Net project (using System.Management.Automation.Powershell)
When running the script in powershell command line, or running the .net project directly from the visual studio the script works, however when publishing the .net project and running the published version it fails.
I receive the error while attempting to bind a parameter to the New-CimSession cmdlet generated by the New-CimSessionOption cmdlet. The New-CimSessionOption generates an object of type DComSessionOptions which is inherits the expected CimSessionOptions however it seems that it got deserialized (lost fidelity) and therefore the parameter failed to bind.
I have made several attempts to fix this using casting as well as create the dcom options my self and pass it explicitly as DComSessionOptions. In all cases attempting to run New-CimSession fails on the same error.
`
$SessionOption = New-CimSessionOption -Culture $Script:InvariantCulture -UICulture $Script:InvariantCulture -Protocol DCOM
$sessionParameters = @{
ComputerName = $ComputerAddress
SessionOption = $DcomOptions
Credential = $credentials
}
Published using:
dotnet publish C:\repos\WMI\WMITester\WMITester.csproj -c Release -r win7-x64 -o .\publish\WMITester\win\Release\x64 /p:PublishSingleFile=True /p:IncludeNativeLibrariesForSelfExtract=true /p:IncludeAllContentForSelfExtract=true /p:SelfContained=true /p:BuildNumber=8
Expected behavior
Actual behavior
$session is null error detailed bellow.Error details
Cannot bind parameter 'SessionOption'. Cannot convert value "Microsoft.Management.Infrastructure.Options.DComSessionOptions" to type "Microsoft.Management.Infrastructure.Options.CimSessionOptions". Error: "Cannot convert the "Microsoft.Management.Infrastructure.Options.DComSessionOptions" value of type "Deserialized.Microsoft.Management.Infrastructure.Options.DComSessionOptions" to type "Microsoft.Management.Infrastructure.Options.CimSessionOptions"Environment data
Visuals
No response