Ace*_*ity 6 arrays powershell powercli
我无法在Start-Job中将数组传递给scriptblock.你能告诉我我可能做错了什么吗?
$bounceBlock = {
param(
[string[]]$list,
[System.Management.Automation.PSCredential]$cred
)
Add-PSSnapin VMware.VimAutomation.Core | Out-Null
Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Scope User -InvalidCertificateAction Ignore -Confirm:$false | Out-Null
Connect-VIServer -Server servername -Credential $cred -AllLinked
Get-VM -Name $list
}
if ($targets) {
$activeTargets = $targets | Get-Random -Count $prodTargets.Count
$counter = [pscustomobject] @{Value = 0}
$groupSize = 50
$groups = $activeTargets | Group-Object -Property {[math]::Floor($counter.Value++ / $groupSize)}
$connection = Connect-VIServer -Server servername -Credential $cred -AllLinked
if ($connection -match "servername") {
    foreach ($group in $groups) {
        while ((Get-Job -State Running).Count -ge 5) {
            Start-Sleep -Seconds 5
            }
        Start-Job -ScriptBlock $bounceBlock -ArgumentList (,$group.Group.ServerName),$cred
        }
    Disconnect-VIServer * -Force -Confirm:$false
    }
}
Run Code Online (Sandbox Code Playgroud)
我基本上将一个数组分成50个(工作)的块,然后尝试将它们作为作业运行.我得到的错误看起来正在尝试为单个服务器运行Get-VM,将所有50个值命名为附加在一起.
|   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           274 次  |  
        
|   最近记录:  |