scripts/AD_GROUPS_CREATE.ps1 gelöscht
This commit is contained in:
@@ -1,169 +0,0 @@
|
||||
$runAsAdmin = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator
|
||||
|
||||
if (-not $runAsAdmin.IsInRole($adminRole)) {
|
||||
# Relaunch the script as Administrator
|
||||
$arguments = "$($myinvocation.MyCommand.Definition)"
|
||||
Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File $arguments" -Verb RunAs
|
||||
exit
|
||||
}
|
||||
|
||||
Add-Type -AssemblyName System.Windows.Forms
|
||||
Import-Module ActiveDirectory
|
||||
|
||||
# Holen Sie sich die Domäne aus dem Active Directory
|
||||
$domain = (Get-ADDomain).DNSRoot
|
||||
|
||||
# GUI erstellen
|
||||
$form = New-Object System.Windows.Forms.Form
|
||||
$form.Text = "Gruppen Erstellung"
|
||||
$form.Size = New-Object System.Drawing.Size(600, 555) # Gesamtgröße der Form anpassen
|
||||
|
||||
# DataGridView für Gruppen erstellen
|
||||
$dataGridView = New-Object System.Windows.Forms.DataGridView
|
||||
$dataGridView.Size = New-Object System.Drawing.Size(564, 300) # Breite und Höhe des DataGridViews
|
||||
$dataGridView.Location = New-Object System.Drawing.Point(10, 10) # Position des DataGridViews
|
||||
$form.Controls.Add($dataGridView)
|
||||
|
||||
# Definieren der Spalten für die DataGridView
|
||||
$dataGridView.ColumnCount = 3
|
||||
$dataGridView.Columns[0].Name = "Typ" # Typ in der ersten Spalte
|
||||
$dataGridView.Columns[1].Name = "Gruppenname" # Gruppenname in der zweiten Spalte
|
||||
$dataGridView.Columns[2].Name = "OU" # OU in der dritten Spalte
|
||||
|
||||
# Breite der Spalten festlegen
|
||||
$dataGridView.Columns[0].Width = 75 # Typ-Spalte auf 50 Pixel setzen
|
||||
$dataGridView.Columns[1].Width = 100 # Gruppenname-Spalte auf 100 Pixel setzen
|
||||
$dataGridView.Columns[2].Width = 345 # OU-Spalte auf 400 Pixel setzen
|
||||
|
||||
# Dropdown für den Typ (GG oder DL)
|
||||
$typColumn = New-Object System.Windows.Forms.DataGridViewComboBoxColumn
|
||||
$typColumn.HeaderText = "Typ"
|
||||
$typColumn.Items.Add("GG")
|
||||
$typColumn.Items.Add("DL")
|
||||
$typColumn.Items.Add("DL_OS")
|
||||
$dataGridView.Columns.RemoveAt(0)
|
||||
$dataGridView.Columns.Insert(0, $typColumn)
|
||||
# Breite der Typ-Spalte setzen
|
||||
$typColumn.Width = 75 # Du kannst hier den Wert nach Bedarf anpassen
|
||||
|
||||
# Dropdown für die OU-Auswahl in der dritten Spalte
|
||||
$ouColumn = New-Object System.Windows.Forms.DataGridViewComboBoxColumn
|
||||
$ouColumn.HeaderText = "OU"
|
||||
$groupOUList = Get-ADOrganizationalUnit -Filter * | Select-Object -ExpandProperty DistinguishedName
|
||||
foreach ($ou in $groupOUList) {
|
||||
$ouColumn.Items.Add($ou)
|
||||
}
|
||||
$dataGridView.Columns.RemoveAt(2)
|
||||
$dataGridView.Columns.Insert(2, $ouColumn)
|
||||
|
||||
# Breite der OU-Spalte setzen
|
||||
$ouColumn.Width = 345 # Du kannst hier den Wert nach Bedarf anpassen
|
||||
|
||||
# RichTextBox für Ausgaben
|
||||
$outputTextBox = New-Object System.Windows.Forms.RichTextBox
|
||||
$outputTextBox.Multiline = $true
|
||||
$outputTextBox.Location = New-Object System.Drawing.Point(10, 320) # Position unterhalb des DataGridViews
|
||||
$outputTextBox.Size = New-Object System.Drawing.Size(564, 150) # Größe der RichTextBox
|
||||
$outputTextBox.ScrollBars = 'Vertical'
|
||||
$form.Controls.Add($outputTextBox)
|
||||
|
||||
# OK-Button für Gruppen erstellen
|
||||
$okButton = New-Object System.Windows.Forms.Button
|
||||
$okButton.Text = "Gruppen erstellen"
|
||||
$okButton.Size = New-Object System.Drawing.Size(280, 30) # Größe des Buttons
|
||||
$okButton.Location = New-Object System.Drawing.Point(10, 475) # Position des Buttons
|
||||
$okButton.Add_Click({
|
||||
foreach ($row in $dataGridView.Rows) {
|
||||
if ($row.Index -lt $dataGridView.RowCount - 1) { # Nicht für die leere letzte Zeile
|
||||
$groupType = $row.Cells[0].Value
|
||||
$groupName = $row.Cells[1].Value
|
||||
$groupOU = $row.Cells[2].Value
|
||||
|
||||
if (-not $groupType -or -not $groupName -or -not $groupOU) {
|
||||
$outputTextBox.SelectionColor = 'Red'
|
||||
$outputTextBox.AppendText("Fehler: Alle Felder (Typ, Gruppenname, OU) müssen ausgefüllt sein.`r`n")
|
||||
continue
|
||||
}
|
||||
|
||||
# Präfix vor den Gruppennamen setzen, basierend auf dem Typ
|
||||
if ($groupType -eq "GG") {
|
||||
$groupName = "GG_" + $groupName # Für globale Gruppen "GG_" voranstellen
|
||||
} elseif ($groupType -eq "DL_OS") {
|
||||
$groupName = "DL_" + $groupName # Für globale Gruppen "DL_OS" voranstellen
|
||||
} elseif ($groupType -eq "DL") {
|
||||
$groupName = "DL_" + $groupName # Für DomainLocal Gruppen "DL_" voranstellen
|
||||
}
|
||||
|
||||
try {
|
||||
if ($groupType -eq "GG") {
|
||||
# Globale Gruppe erstellen (keine Suffixe, aber Präfix wird hinzugefügt)
|
||||
$group = Get-ADGroup -Filter { Name -eq $groupName }
|
||||
if (-not $group) {
|
||||
New-ADGroup -Name $groupName `
|
||||
-GroupScope Global `
|
||||
-Path $groupOU `
|
||||
-Description "Globale Gruppe für $groupName"
|
||||
$outputTextBox.SelectionColor = 'Green'
|
||||
$outputTextBox.AppendText("Globale Gruppe '$groupName' wurde erfolgreich erstellt.`r`n")
|
||||
} else {
|
||||
$outputTextBox.SelectionColor = 'Green'
|
||||
$outputTextBox.AppendText("Globale Gruppe '$groupName' existiert bereits.`r`n")
|
||||
}
|
||||
} elseif ($groupType -eq "DL_OS") {
|
||||
# DomainLocal Gruppen ohne Suffix erstellen
|
||||
$domainLocalGroupName = "$groupName"
|
||||
if (-not $group) {
|
||||
New-ADGroup -Name $domainLocalGroupName `
|
||||
-GroupScope DomainLocal `
|
||||
-Path $groupOU `
|
||||
-Description "DomainLocal Gruppe für $domainLocalGroupName"
|
||||
$outputTextBox.SelectionColor = 'Green'
|
||||
$outputTextBox.AppendText("DomainLocal Gruppe '$domainLocalGroupName' wurde erfolgreich erstellt.`r`n")
|
||||
} else {
|
||||
$outputTextBox.SelectionColor = 'Green'
|
||||
$outputTextBox.AppendText("DomainLocal Gruppe '$domainLocalGroupName' existiert bereits.`r`n")
|
||||
}
|
||||
} elseif ($groupType -eq "DL") {
|
||||
# DomainLocal Gruppen mit Suffixen erstellen
|
||||
$suffixes = "_FA", "_RW", "_RX", "_RO"
|
||||
foreach ($suffix in $suffixes) {
|
||||
$domainLocalGroupName = "$groupName$suffix"
|
||||
$group = Get-ADGroup -Filter { Name -eq $domainLocalGroupName }
|
||||
if (-not $group) {
|
||||
New-ADGroup -Name $domainLocalGroupName `
|
||||
-GroupScope DomainLocal `
|
||||
-Path $groupOU `
|
||||
-Description "DomainLocal Gruppe für $domainLocalGroupName"
|
||||
$outputTextBox.SelectionColor = 'Green'
|
||||
$outputTextBox.AppendText("DomainLocal Gruppe '$domainLocalGroupName' wurde erfolgreich erstellt.`r`n")
|
||||
} else {
|
||||
$outputTextBox.SelectionColor = 'Green'
|
||||
$outputTextBox.AppendText("DomainLocal Gruppe '$domainLocalGroupName' existiert bereits.`r`n")
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
# Fehler bei der Gruppen-Erstellung
|
||||
$outputTextBox.SelectionColor = 'Red'
|
||||
$outputTextBox.AppendText("Fehler bei der Erstellung der Gruppe '$groupName': $_.Exception.Message`r`n")
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
# Beenden-Button erstellen
|
||||
$exitButton = New-Object System.Windows.Forms.Button
|
||||
$exitButton.Text = "Beenden"
|
||||
$exitButton.Size = New-Object System.Drawing.Size(280, 30)
|
||||
$exitButton.Location = New-Object System.Drawing.Point(295, 475) # Position des Beenden-Buttons
|
||||
$exitButton.Add_Click({
|
||||
$form.Close() # Formular schließen
|
||||
})
|
||||
|
||||
# Buttons zum Formular hinzufügen
|
||||
$form.Controls.Add($okButton)
|
||||
$form.Controls.Add($exitButton)
|
||||
|
||||
# Formular anzeigen
|
||||
$form.ShowDialog()
|
||||
Reference in New Issue
Block a user