I want to loop through groups first set of values in each group, then loop through the next set of values. I have a Cluster with 4 physical Nodes, that hosts 8 Sql Server Instances, 2 Instances per Node. I want to run a script on each Instance, on each Node. But I only want to run the script on 1 Instance per Node at a time. So run it on Inst01 on Node01, Inst02 on Node02, Inst03 on Node 03 and on Inst04 on Node 04 , I’ll use start-job for each. Then, once each job has completed, loop through the next group and run it on Inst11 on Node01, Inst12 on Node02, Inst13 on Node03 and Inst14 on Node04 , using start-job.
The information about the Instances and Nodes come from this
$Instances = @() foreach($SqlInstance in $SqlServers | ?{$_ -Match 'PROD'} ) { [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null $Srv = New-Object ("Microsoft.SqlServer.Management.Smo.Server") $sqlInstance $Instances += [PSCustomObject]@{ Instance = $Srv.DomainInstanceName IsClustered = $srv.IsClustered PhysicalHost = $Srv.ComputerNamePhysicalNetBIOS } } $Groups = $Instances | Group PhysicalHost foreach($Obj in $groups) { for ($i=0; $i -le $Obj.Count; $i++) { $obj.Group.Instance[$i] $obj.Group.PhysicalHost[$i] } }
Which gives me
INSTP10\ROD10 NODE-P01 INSTP03\PROD03 NODE-P01 INSTP11\PROD11 NODE-P03 INSTP07\PROD07 NODE-P03 INSTP04\PROD04 NODE-P02 INSTP05\PROD05 NODE-P02 INSTP06\PROD06 NODE-P04 INSTP08\ROD08 NODE-P04
How can I loop through that group taking only 1 Instance per Node but next loop take the next in the group for each node ?