Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2314

Mehrere Schleifen verschachteln

$
0
0

Hallo,

ich brauche etwas Hilfe.

In meinem Script lese ich, gefiltert, PC Namen aus einer Datenbank aus. In Summe brauche ich 750 PC Namen die ich in 5 Gruppen a 50 PC Namen und 5 Gruppen a 100 PC Namen verteile. Soweit funktioniert auch alles.

Wenn ich diese Gruppen habe, dann sollen die einzelnen PCs Mitglied einer weiteren Gruppe werden. Ich habe also 10 Gruppennamen.

Ich müsste also die 10 Gruppennamen auslesen, die ersten 50 PCs in die erste Gruppe stecken, dann den zweiten Gruppennamen auslesen und die nächsten 50 PCs in diese Gruppe stecken usw. aber das bekomme ich irgendwie nicht hin.

Kann mir jemand helfen?

$x = 50
$ReportFile = "D:\Powershell\Report\Office2007_" + $x + ".txt"
$Office_Gruppen = "D:\Powershell\Quelle\Office_2007_Gruppen.txt"
cd "emdb:\rootDSE\Managed Users & Computers\Clients\Alle Computer"
$file = Get-EmdbComputer -Recurse -Filter "(&(!(Computer.OperationMode=0))(BasicInventory.LastKnownSite=66010)(!(Name:IgnoreCase=TLWK*))(!(Name:IgnoreCase=nb*))(BasicInventory.LastSyncDate:UtcDateTime>=2014-12-31T23:00:00)(!(Name:IgnoreCase=*-*))objectCategory=Computer))"
$group = Get-Content $Gruppen

$i = 0
$e = 749
$w = 249
$x = 49
$y = 100
$z = 50

# einlesen der PC Namen
foreach ($computername in $file)
        {
        $i = $i + 1
        Write-Host $i $computername.name
        $computername.name | Out-File -FilePath $ReportFile -Append
        $ReportFile = "D:\Powershell\Report\Office2007_" + $x + ".txt"
        If ($i -ge $e)
           {Exit
           }
        If ($i -ge $x)
           {
            If ($i -ge $w)
                {
                $x = $x + $y
                $ReportFile | Out-File -FilePath $Office_Gruppen -Append
                }
            else
               {
                $x = $x + $z
                $ReportFile | Out-File -FilePath $Office_Gruppen -Append
           }
          }
        }


IT Berater


Viewing all articles
Browse latest Browse all 2314

Latest Images

Trending Articles