Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

DComSessionOptions and CimSessionOptions in Workflow

$
0
0

This question is a cross between WMI (via CIM) and Workflow.  I hope I picked a reasonable forum.

My code looks for a specific service on a set of machines.  I am able to get this to work using Get-WMIObject in a workflow as in the following:

workfloww1 {

    param([string[]]$computerName)

    foreach  -parallel($computerin$computerName) {

        Get-WmiObject-PSComputerName$computer-ClassWin32_Service-filter"Name = 'Dhcp'"|Select-propertyName, @{n="Computer";e={"$($_.SystemName)"}}

    }

}

$computerList= @("Computer1"," Computer2"," Computer3")

W1-computerName$computerList|Select-ObjectName,Computer

I wanted to try using the CIM activities also and see if there is any performance difference.  (I was suprised to see an indication for a small number of machines that the workflow seemed to perform faster than letting Get-WmiObject use its own job capabilities by passing in multiple computers.)  I do need to fall back to DCOM being PowerShell is not on all the machines.  This is what I came up with:

$computerList= @("Computer1"," Computer2"," Computer3")

$opt=New-CimSessionOption-ProtocolDCOM

foreach ($computerin$computerList) {

    $sd=New-CimSession-ComputerName$computer-SessionOption$opt

    Get-CimInstance-CimSession$sd-ClassNameWin32_Service-filter"Name = 'Dhcp'"|Select-propertyName, @{n="Computer";e={"$($_.SystemName)"}}

}

That works fine also and uses the CIM cmdlets.  Then I run into a problem making this a workflow.  The following is my attempt:

workfloww2 {

    param([string[]]$computerName)

    $opt=New-CimSessionOption-ProtocolDCOM

    foreach ($computerin$computerName) {

        $sd=New-CimSession-PSComputerName$computer-SessionOption$opt

        Get-CimInstance-CimSession$sd-ClassNameWin32_Service-filter"Name = 'Dhcp'"|Select-propertyName, @{n="Computer";e={"$($_.SystemName)"}}

    }

}

$computerList= @("Computer1"," Computer2"," Computer3")

w2-computerName$computerList|Select-ObjectName,Computer

That fails with:

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"."

    + CategoryInfo          : InvalidArgument: (:) [], ParentContainsErrorRecordException

    + FullyQualifiedErrorId : InvalidCastConstructorException

    + PSComputerName        : [localhost]

There is nothing in the help for New-CimSessionOption cmdlet that says anything about returning different types--hopefully the New-CimSessionOption activity would be the same.  That may be the problem though.  I looked at the types in MSDN and those two types do have a different set of properties (DcomSessionOptions has more).

Why would PowerShell need to convert the options when running in a workflow when it does not need to (or have a problem doing so) when not in a workflow?

 Steve


Viewing all articles
Browse latest Browse all 8583

Trending Articles