0
votes

I have written a script to get the offline cluster resources using foreach syntax and it is working fine. But I need to get the cluster offline resources for 50 clusters and I have tried foreach -parallel and got an error.

workflow Test-Workflow {
    Param ([string[]] $clusters)
    $clusters = Get-Content "C:\temp\Clusters.txt"
    foreach -parallel ($cluster in $clusters) {
        $clu1 = Get-Cluster -Name $cluster
        $clustername = $clu1.Name
        echo $clustername
        $clu2 = Get-Cluster $clustername |
                Get-ClusterResource |
                where { $_.Name -and $_.state -eq "offline" }
        echo $clu2
    }
}
Test-Workflow

Output:

slchypervcl003
slchypervcl004
Get-ClusterResource : The input object cannot be bound to any parameters for
the command either because the command does not take pipeline input or the
input and its properties do not match any of the parameters that take pipeline
input.
At Test-Workflow:8 char:8
+ 
    + CategoryInfo          : InvalidArgument: (slchypervcl003:PSObject) [Get-ClusterResource], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.FailoverClusters.PowerShell.GetResourceCommand
    + PSComputerName        : [localhost]

Get-ClusterResource : The input object cannot be bound to any parameters for
the command either because the command does not take pipeline input or the
input and its properties do not match any of the parameters that take pipeline
input.
At Test-Workflow:8 char:8
+ 
    + CategoryInfo          : InvalidArgument: (slchypervcl004:PSObject) [Get-ClusterResource], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.FailoverClusters.PowerShell.GetResourceCommand
    + PSComputerName        : [localhost]
1

1 Answers

2
votes

Get-ClusterResource can only take a cluster node object or cluster group object as a pipeline input, which is passed to the -InputObject parameter. The Get-Cluster command returns an object type Microsoft.FailoverClusters.PowerShell.Cluster instead of the required Microsoft.FailoverClusters.PowerShell.ClusterResource or Microsoft.FailoverClusters.PowerShell.ClusterNode object for pipeline input into Get-ClusterResource. If you altered your code to not use a pipeline and just gave it cluster name as a parameter value, how do your results vary?

Change the following:

$clu2 = Get-Cluster $clustername | Get-ClusterResource | where { $_.Name - 
and $_.state -eq "offline"}

To:

$clu2 = Get-ClusterResource -Name $clustername | where { $_.Name - 
and $_.state -eq "offline"}

Or:

$clu2 = Get-ClusterResource -Cluster $clustername | where { $_.Name - 
and $_.state -eq "offline"}