From c2d8da4583e583e1f9ef716124552a0e8b8f447e Mon Sep 17 00:00:00 2001 From: Tim Eertmoed Date: Wed, 6 Nov 2024 14:51:48 +0100 Subject: [PATCH] =?UTF-8?q?scripts/ad=5Fgg+lg.ps1=20gel=C3=B6scht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/ad_gg+lg.ps1 | 113 ------------------------------------------- 1 file changed, 113 deletions(-) delete mode 100644 scripts/ad_gg+lg.ps1 diff --git a/scripts/ad_gg+lg.ps1 b/scripts/ad_gg+lg.ps1 deleted file mode 100644 index 4eb9a1d..0000000 --- a/scripts/ad_gg+lg.ps1 +++ /dev/null @@ -1,113 +0,0 @@ -# Erforderliche Assemblies laden -Add-Type -AssemblyName System.Windows.Forms -Add-Type -AssemblyName System.Drawing - -# Formular erstellen -$form = New-Object System.Windows.Forms.Form -$form.Text = "Gruppen-Erstellung" -$form.Size = New-Object System.Drawing.Size(1200, 650) -$form.StartPosition = "CenterScreen" -$form.BackColor = [System.Drawing.Color]::White - -# DataGridView erstellen -$dataGridView = New-Object System.Windows.Forms.DataGridView -$dataGridView.Size = New-Object System.Drawing.Size(1150, 450) -$dataGridView.Location = New-Object System.Drawing.Point(15, 15) -$dataGridView.ColumnCount = 4 - -# Spaltenüberschriften festlegen -$dataGridView.Columns[0].Name = "Type" -$dataGridView.Columns[1].Name = "GroupName" -$dataGridView.Columns[2].Name = "OU" -$dataGridView.Columns[3].Name = "DC" - -# Beispielzeilen hinzufügen -$dataGridView.Rows.Add("Master", "DefaultGroup", "DefaultOU", "DC=yourdomain,DC=com") -$dataGridView.Rows.Add("GG", "", "", "") -$dataGridView.Rows.Add("LG", "", "", "") - -# DataGridView anpassen -$dataGridView.AlternatingRowsDefaultCellStyle.BackColor = [System.Drawing.Color]::LightGray - -# Eventhandler hinzufügen -$dataGridView.add_CellEndEdit({ - param ($sender, $e) - $row = $dataGridView.Rows[$e.RowIndex] - - # OU und DC vom darüberliegenden Master übernehmen - if ($row.Cells["Type"].Value -ne 'Master') { - for ($i = ($e.RowIndex - 1); $i -ge 0; $i--) { - if ($dataGridView.Rows[$i].Cells["Type"].Value -eq 'Master') { - $masterRow = $dataGridView.Rows[$i] - $row.Cells["OU"].Value = $masterRow.Cells["OU"].Value - $row.Cells["DC"].Value = $masterRow.Cells["DC"].Value - break - } - } - - # Typ basierend auf dem Gruppentyp festlegen - if ($row.Cells["Type"].Value -eq 'GG') { - $row.Cells["GroupType"].Value = 'Global' - } elseif ($row.Cells["Type"].Value -eq 'LG') { - $row.Cells["GroupType"].Value = 'Local' - } - } -}) - -# OK-Button -$okButton = New-Object System.Windows.Forms.Button -$okButton.Text = "OK" -$okButton.Location = New-Object System.Drawing.Point(550, 500) -$okButton.BackColor = [System.Drawing.Color]::White -$okButton.FlatStyle = "Flat" -$okButton.Add_Click({ - $form.Close() -}) -$form.Controls.Add($okButton) - -# DataGridView zum Formular hinzufügen -$form.Controls.Add($dataGridView) - -# Formular anzeigen -$form.ShowDialog() - -# Eingabedaten extrahieren -$data = @() -foreach ($row in $dataGridView.Rows) { - if (-not $row.IsNewRow) { - $data += [PSCustomObject]@{ - Type = $row.Cells[0].Value - GroupName = $row.Cells[1].Value - OU = $row.Cells[2].Value - DC = $row.Cells[3].Value - GroupType = if ($row.Cells[0].Value -eq 'GG') { 'Global' } else { 'Local' } - } - } -} - -# Liste für erstellte Gruppen -$createdGroups = @() - -# Durchlaufen jeder Zeile der Daten und Gruppen erstellen -foreach ($row in $data) { - if ($row.Type -ne 'Master') { - $path = "OU=$($row.OU),DC=$($row.DC)" - - if ($row.Type -eq 'GG') { - # Globale Gruppe erstellen - $newGroup = New-ADGroup -Name $row.GroupName -GroupScope 'Global' -Path $path - $createdGroups += $newGroup - } elseif ($row.Type -eq 'LG') { - # Lokale Gruppen mit Suffixen erstellen - $groupNames = @($row.GroupName + '_FA', $row.GroupName + '_RW', $row.GroupName + '_RX', $row.GroupName + '_RO') - foreach ($groupName in $groupNames) { - $newGroup = New-ADGroup -Name $groupName -GroupScope 'Local' -Path $path - $createdGroups += $newGroup - } - } - } -} - -# Erstellte Gruppen anzeigen -Write-Host "`nErstellte Gruppen:" -ForegroundColor Green -$createdGroups | ForEach-Object { Write-Host $_.Name -ForegroundColor Green }