foreach - параллель в PowerShell - PullRequest
0 голосов
/ 04 марта 2019

Я написал скрипт для получения ресурсов автономного кластера с использованием синтаксиса foreach, и он работает нормально.Но мне нужно получить кластерные автономные ресурсы для 50 кластеров, и я попытался foreach -parallel и получил ошибку.

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

Вывод:

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 Ответ

0 голосов
/ 04 марта 2019

Get-ClusterResource может принимать только объект узла кластера или объект группы кластеров в качестве входных данных конвейера, которые передаются параметру -InputObject.Команда Get-Cluster возвращает тип объекта Microsoft.FailoverClusters.PowerShell.Cluster вместо обязательного Microsoft.FailoverClusters.PowerShell.ClusterResource или Microsoft.FailoverClusters.PowerShell.ClusterNode объект для ввода конвейера в Get-ClusterResource.Если вы изменили свой код так, чтобы он не использовал конвейер, и просто дали ему имя кластера в качестве значения параметра, как ваши результаты изменятся?

Измените следующее:

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

На:

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

Или:

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