mattifestation/CimSweep

Get-CSRegistryAutoStart parameter CimSession type is invalid

haroldogden opened this issue · 7 comments

On line 137:
[Microsoft.Management.Infrastructure.CimSession[]]

Works when changed to:
[Microsoft.Management.Infrastructure.CimSession]

Can you tell me how you're invoking it? All CimSweep functions need to accept an array of CimSession arguments so I can't change it from an array type.

The following are working fine for me:

Get-CSRegistryAutoStart -CimSession $CimSession, $CimSession2
Get-CSRegistryAutoStart -CimSession $CimSession
Get-CSRegistryAutoStart

Any detailed error information you can provide would be very helpful. Thanks for testing CimSweep, by the way!

No problem, thank you for the great module! Once I'm back at the system where I had the issue, I will reproduce and post more details.

PS C:\windows\System32\WindowsPowerShell\v1.0> $testinstance = New-CimSession -ComputerName hostname.testdomain.local
PS C:\windows\System32\WindowsPowerShell\v1.0> Get-CSWmiPersistence -CimSession $testinstance
Get-CSWmiPersistence : Cannot process argument transformation on parameter 'CimSession'. Cannot convert value to type
"Microsoft.Management.Infrastructure.CimSession[]". Only core types are supported in this language mode.
At line:1 char:34
+ Get-CSWmiPersistence -CimSession $testinstance
+                                  ~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Get-CSWmiPersistence], ParameterBindingArgumentTransformationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-CSWmiPersistence

PS C:\windows\System32\WindowsPowerShell\v1.0>




PS C:\windows\System32\WindowsPowerShell\v1.0> $testinstance


Id           : 1
Name         : CimSession1
InstanceId   : 85205521-240f-43da-a5b6-1ca807c0be05
ComputerName : hostname.testdomain.local
Protocol     : WSMAN

PS C:\windows\System32\WindowsPowerShell\v1.0> Get-CSRegistryAutoStart -CimSession $testinstance
Get-CSRegistryAutoStart : Cannot process argument transformation on parameter 'CimSession'. Cannot convert value to type "Microsoft.Management.Infrastructure.CimSession[]". Only
core types are supported in this language mode.
At line:1 char:37
+ Get-CSRegistryAutoStart -CimSession $testinstance
+                                     ~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Get-CSRegistryAutoStart], ParameterBindingArgumentTransformationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-CSRegistryAutoStart

Thanks for the detailed output. Oh boy. It looks like you're operating in constrained language mode which can be confirmed with the following:

$Host.Runspace.LanguageMode

Also read Get-Help about_Language_Modes for additional information.

I haven't tested CimSweep from within constrained language mode. I'll test it soon and see what the feasibility of supporting it is but I can't guarantee that I'll be able to support it. If you run into any issues in FullLanguage mode, please let me know. Thanks!

I'll update you via this thread if I have any updates re. constrained language mode support.

The problem seems to get even worse. I was testing in constrained language mode and apparently, you can't even use the CIM cmdlets. Sigh. This is totally Microsoft's problem. I was hoping I might be able to make some tweaks but I don't think I'll be able to. So you were able to call New-CimSession? I can't call it since constrained language mode won't import the CimCmdlets module.

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.0.10586.122
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.10586.122
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


PS C:\> $Host.Runspace.LanguageMode
ConstrainedLanguage
PS C:\> Import-Module CimCmdlets
Import-Module : Cannot create type. Only core types are supported in this language mode.
At line:1 char:1
+ Import-Module CimCmdlets
+ ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], RuntimeException
    + FullyQualifiedErrorId : CannotCreateTypeConstrainedLanguage,Microsoft.PowerShell.Commands.ImportModuleCommand

I was able to import and use the module as long as I changed
[Microsoft.Management.Infrastructure.CimSession[]]
to
[Microsoft.Management.Infrastructure.CimSession]
I can create new variables from the new-cimsession cmdlet, use the get-cswmipersistence cmdlets, etc.

However, I suspect constrained language mode is going to impact more than just this module, so I will fix that on my end and continue testing.