scripts/AD_AIO.ps1 aktualisiert
This commit is contained in:
@@ -29,19 +29,49 @@ function Create-User {
|
|||||||
# GUI erstellen
|
# GUI erstellen
|
||||||
$form = New-Object System.Windows.Forms.Form
|
$form = New-Object System.Windows.Forms.Form
|
||||||
$form.Text = "Benutzererstellung"
|
$form.Text = "Benutzererstellung"
|
||||||
$form.Size = New-Object System.Drawing.Size(800, 600) # Gesamtgröße der Form anpassen
|
$form.Size = New-Object System.Drawing.Size(990, 600) # Gesamtgröße der Form anpassen
|
||||||
|
|
||||||
|
# Funktion zur Berechnung der maximalen Breite der ComboBox
|
||||||
|
function Set-DropDownWidth {
|
||||||
|
param (
|
||||||
|
[System.Windows.Forms.ComboBox]$comboBox
|
||||||
|
)
|
||||||
|
|
||||||
|
$maxLength = 0
|
||||||
|
foreach ($item in $comboBox.Items) {
|
||||||
|
$itemLength = $item.Length
|
||||||
|
if ($itemLength -gt $maxLength) {
|
||||||
|
$maxLength = $itemLength
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Setze die DropDownWidth entsprechend der maximalen Länge
|
||||||
|
$comboBox.DropDownWidth = $maxLength * 6 # Schätzbreite (Zeichen * 8 Pixel)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Masterkennwort Eingabefeld
|
||||||
|
$masterPasswordLabel = New-Object System.Windows.Forms.Label
|
||||||
|
$masterPasswordLabel.Text = "Masterkennwort:"
|
||||||
|
$masterPasswordLabel.Location = New-Object System.Drawing.Point(10, 12)
|
||||||
|
$masterPasswordLabel.Size = New-Object System.Drawing.Size(100, 20)
|
||||||
|
$form.Controls.Add($masterPasswordLabel)
|
||||||
|
|
||||||
|
$masterPasswordTextBox = New-Object System.Windows.Forms.TextBox
|
||||||
|
$masterPasswordTextBox.Location = New-Object System.Drawing.Point(110, 10)
|
||||||
|
$masterPasswordTextBox.Size = New-Object System.Drawing.Size(200, 20)
|
||||||
|
$masterPasswordTextBox.UseSystemPasswordChar = $true # Passwortfeld
|
||||||
|
$form.Controls.Add($masterPasswordTextBox)
|
||||||
|
|
||||||
# Master-OU für Benutzer Auswahl
|
# Master-OU für Benutzer Auswahl
|
||||||
$masterOULabel = New-Object System.Windows.Forms.Label
|
$masterOULabel = New-Object System.Windows.Forms.Label
|
||||||
$masterOULabel.Text = "Master-OU (Benutzer):"
|
$masterOULabel.Text = "Master-OU (Benutzer):"
|
||||||
$masterOULabel.Location = New-Object System.Drawing.Point(10, 10)
|
$masterOULabel.Location = New-Object System.Drawing.Point(320, 12)
|
||||||
$masterOULabel.Size = New-Object System.Drawing.Size(120, 20)
|
$masterOULabel.Size = New-Object System.Drawing.Size(120, 20)
|
||||||
$form.Controls.Add($masterOULabel)
|
$form.Controls.Add($masterOULabel)
|
||||||
|
|
||||||
# Master-OU ComboBox für Benutzer
|
|
||||||
$masterOUComboBox = New-Object System.Windows.Forms.ComboBox
|
$masterOUComboBox = New-Object System.Windows.Forms.ComboBox
|
||||||
$masterOUComboBox.Location = New-Object System.Drawing.Point(130, 10)
|
$masterOUComboBox.Location = New-Object System.Drawing.Point(440, 10)
|
||||||
$masterOUComboBox.Size = New-Object System.Drawing.Size(250, 20) # ComboBox-Größe festgelegt
|
$masterOUComboBox.Size = New-Object System.Drawing.Size(200, 20) # ComboBox-Größe festgelegt
|
||||||
$masterOUComboBox.DropDownStyle = 'DropDownList'
|
$masterOUComboBox.DropDownStyle = 'DropDownList'
|
||||||
|
|
||||||
# OUs aus dem AD für Benutzer abrufen und in die ComboBox einfügen
|
# OUs aus dem AD für Benutzer abrufen und in die ComboBox einfügen
|
||||||
@@ -50,17 +80,19 @@ function Create-User {
|
|||||||
$masterOUComboBox.SelectedItem = $masterOU # Standardwerte setzen
|
$masterOUComboBox.SelectedItem = $masterOU # Standardwerte setzen
|
||||||
$form.Controls.Add($masterOUComboBox)
|
$form.Controls.Add($masterOUComboBox)
|
||||||
|
|
||||||
# Master-OU für Gruppen Auswahl (Rechts oben)
|
# Berechne und setze die DropDownWidth basierend auf der maximalen Länge
|
||||||
|
Set-DropDownWidth -comboBox $masterOUComboBox
|
||||||
|
|
||||||
|
# Master-OU für Gruppen Auswahl
|
||||||
$masterGroupOULabel = New-Object System.Windows.Forms.Label
|
$masterGroupOULabel = New-Object System.Windows.Forms.Label
|
||||||
$masterGroupOULabel.Text = "Master-OU (Gruppen):"
|
$masterGroupOULabel.Text = "Master-OU (Gruppen):"
|
||||||
$masterGroupOULabel.Location = New-Object System.Drawing.Point(400, 10)
|
$masterGroupOULabel.Location = New-Object System.Drawing.Point(645, 12)
|
||||||
$masterGroupOULabel.Size = New-Object System.Drawing.Size(120, 20)
|
$masterGroupOULabel.Size = New-Object System.Drawing.Size(120, 20)
|
||||||
$form.Controls.Add($masterGroupOULabel)
|
$form.Controls.Add($masterGroupOULabel)
|
||||||
|
|
||||||
# Master-OU ComboBox für Gruppen
|
|
||||||
$masterGroupOUComboBox = New-Object System.Windows.Forms.ComboBox
|
$masterGroupOUComboBox = New-Object System.Windows.Forms.ComboBox
|
||||||
$masterGroupOUComboBox.Location = New-Object System.Drawing.Point(520, 10)
|
$masterGroupOUComboBox.Location = New-Object System.Drawing.Point(765, 10)
|
||||||
$masterGroupOUComboBox.Size = New-Object System.Drawing.Size(250, 20) # ComboBox-Größe für Gruppen
|
$masterGroupOUComboBox.Size = New-Object System.Drawing.Size(200, 20) # ComboBox-Größe für Gruppen
|
||||||
$masterGroupOUComboBox.DropDownStyle = 'DropDownList'
|
$masterGroupOUComboBox.DropDownStyle = 'DropDownList'
|
||||||
|
|
||||||
# OUs aus dem AD für Gruppen abrufen und in die ComboBox einfügen
|
# OUs aus dem AD für Gruppen abrufen und in die ComboBox einfügen
|
||||||
@@ -69,13 +101,25 @@ function Create-User {
|
|||||||
$masterGroupOUComboBox.SelectedItem = $masterGroupOU # Standardwerte setzen
|
$masterGroupOUComboBox.SelectedItem = $masterGroupOU # Standardwerte setzen
|
||||||
$form.Controls.Add($masterGroupOUComboBox)
|
$form.Controls.Add($masterGroupOUComboBox)
|
||||||
|
|
||||||
|
# Berechne und setze die DropDownWidth basierend auf der maximalen Länge
|
||||||
|
Set-DropDownWidth -comboBox $masterGroupOUComboBox
|
||||||
|
|
||||||
# DataGridView erstellen
|
# DataGridView erstellen
|
||||||
$dataGridView = New-Object System.Windows.Forms.DataGridView
|
$dataGridView = New-Object System.Windows.Forms.DataGridView
|
||||||
$dataGridView.Size = New-Object System.Drawing.Size(764, 300) # Breite und Höhe des DataGridViews festgelegt
|
$dataGridView.Size = New-Object System.Drawing.Size(954, 300) # Breite und Höhe des DataGridViews festgelegt
|
||||||
$dataGridView.Location = New-Object System.Drawing.Point(10, 40) # Position des DataGridViews
|
$dataGridView.Location = New-Object System.Drawing.Point(10, 40) # Position des DataGridViews
|
||||||
$dataGridView.Anchor = [System.Windows.Forms.AnchorStyles]::Top
|
$dataGridView.Anchor = [System.Windows.Forms.AnchorStyles]::Top
|
||||||
$form.Controls.Add($dataGridView)
|
$form.Controls.Add($dataGridView)
|
||||||
|
|
||||||
|
# Die Breite der DropDown-Liste manuell anpassen, da DropDownWidth für DataGridViewComboBoxColumn nicht unterstützt wird
|
||||||
|
$maxLength = 0
|
||||||
|
foreach ($item in $masterGroupOUComboBox.Items) {
|
||||||
|
$itemLength = $item.ToString().Length
|
||||||
|
if ($itemLength -gt $maxLength) {
|
||||||
|
$maxLength = $itemLength
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Definieren der Spalten für die DataGridView
|
# Definieren der Spalten für die DataGridView
|
||||||
$dataGridView.ColumnCount = 6
|
$dataGridView.ColumnCount = 6
|
||||||
$dataGridView.Columns[0].Name = "Titel" # Titel in der ersten Spalte
|
$dataGridView.Columns[0].Name = "Titel" # Titel in der ersten Spalte
|
||||||
@@ -84,7 +128,7 @@ function Create-User {
|
|||||||
$dataGridView.Columns[3].Name = "Globalgruppe" # Globalgruppe
|
$dataGridView.Columns[3].Name = "Globalgruppe" # Globalgruppe
|
||||||
$dataGridView.Columns[4].Name = "Standardpasswort" # Standardpasswort
|
$dataGridView.Columns[4].Name = "Standardpasswort" # Standardpasswort
|
||||||
$dataGridView.Columns[5].Name = "OU" # OU (wird als ComboBox hinzugefügt)
|
$dataGridView.Columns[5].Name = "OU" # OU (wird als ComboBox hinzugefügt)
|
||||||
$dataGridView.Columns[5].Width = 220
|
$dataGridView.Columns[5].Width = $ouComboBoxColumn
|
||||||
|
|
||||||
# Dropdown für die OU in der DataGridView-ComboBox-Spalte
|
# Dropdown für die OU in der DataGridView-ComboBox-Spalte
|
||||||
$ouComboBoxColumn = New-Object System.Windows.Forms.DataGridViewComboBoxColumn
|
$ouComboBoxColumn = New-Object System.Windows.Forms.DataGridViewComboBoxColumn
|
||||||
@@ -92,29 +136,13 @@ function Create-User {
|
|||||||
$ouComboBoxColumn.Items.AddRange($ouList) # Hier fügen wir alle OUs hinzu
|
$ouComboBoxColumn.Items.AddRange($ouList) # Hier fügen wir alle OUs hinzu
|
||||||
$dataGridView.Columns.RemoveAt(5) # Entfernt die ursprüngliche OU-Spalte
|
$dataGridView.Columns.RemoveAt(5) # Entfernt die ursprüngliche OU-Spalte
|
||||||
$dataGridView.Columns.Insert(5, $ouComboBoxColumn) # Fügt die ComboBox-Spalte an der richtigen Stelle ein
|
$dataGridView.Columns.Insert(5, $ouComboBoxColumn) # Fügt die ComboBox-Spalte an der richtigen Stelle ein
|
||||||
$ouComboBoxColumn.Width = 220 # Du kannst hier den Wert nach Bedarf anpassen
|
$ouComboBoxColumn.Width = $maxLength * 6
|
||||||
|
|
||||||
# Funktion zum Setzen der OUs für alle Zeilen im DataGridView
|
|
||||||
function Update-OUsInGrid {
|
|
||||||
$selectedMasterOU = $masterOUComboBox.SelectedItem
|
|
||||||
foreach ($row in $dataGridView.Rows) {
|
|
||||||
if ($row.Index -lt $dataGridView.RowCount - 1) { # Nicht für die leere letzte Zeile
|
|
||||||
# Setze die Master-OU in der "OU"-Spalte für jede Zeile
|
|
||||||
$row.Cells[5].Value = $selectedMasterOU # Zeile aktualisieren, statt der 4. Spalte jetzt die 5. für OU
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Master-OU ComboBox geändert: Aktualisiere alle OUs im DataGridView
|
|
||||||
$masterOUComboBox.Add_SelectedIndexChanged({
|
|
||||||
Update-OUsInGrid
|
|
||||||
})
|
|
||||||
|
|
||||||
# RichTextBox für Ausgaben (anstelle von TextBox)
|
# RichTextBox für Ausgaben (anstelle von TextBox)
|
||||||
$outputTextBox = New-Object System.Windows.Forms.RichTextBox
|
$outputTextBox = New-Object System.Windows.Forms.RichTextBox
|
||||||
$outputTextBox.Multiline = $true
|
$outputTextBox.Multiline = $true
|
||||||
$outputTextBox.Location = New-Object System.Drawing.Point(10, 350) # Position unterhalb des DataGridViews
|
$outputTextBox.Location = New-Object System.Drawing.Point(10, 350) # Position unterhalb des DataGridViews
|
||||||
$outputTextBox.Size = New-Object System.Drawing.Size(764, 150) # Größe der RichTextBox festgelegt
|
$outputTextBox.Size = New-Object System.Drawing.Size(954, 150) # Größe der RichTextBox festgelegt
|
||||||
$outputTextBox.ScrollBars = 'Vertical'
|
$outputTextBox.ScrollBars = 'Vertical'
|
||||||
$form.Controls.Add($outputTextBox)
|
$form.Controls.Add($outputTextBox)
|
||||||
|
|
||||||
@@ -123,7 +151,20 @@ function Create-User {
|
|||||||
$okButton.Text = "Benutzer erstellen"
|
$okButton.Text = "Benutzer erstellen"
|
||||||
$okButton.Size = New-Object System.Drawing.Size(380, 30) # Größe des Buttons festgelegt
|
$okButton.Size = New-Object System.Drawing.Size(380, 30) # Größe des Buttons festgelegt
|
||||||
$okButton.Location = New-Object System.Drawing.Point(10, 510) # Position des Buttons unter der TextBox
|
$okButton.Location = New-Object System.Drawing.Point(10, 510) # Position des Buttons unter der TextBox
|
||||||
|
|
||||||
|
# Beenden-Button erstellen
|
||||||
|
$exitButton = New-Object System.Windows.Forms.Button
|
||||||
|
$exitButton.Text = "Beenden"
|
||||||
|
$exitButton.Size = New-Object System.Drawing.Size(380, 30) # Größe des Buttons festgelegt
|
||||||
|
$exitButton.Location = New-Object System.Drawing.Point(585, 510) # Position des Beenden-Buttons
|
||||||
|
|
||||||
|
# Buttons zum Formular hinzufügen
|
||||||
|
$form.Controls.Add($okButton)
|
||||||
|
$form.Controls.Add($exitButton)
|
||||||
|
|
||||||
|
# Event-Handler für den OK-Button hinzufügen
|
||||||
$okButton.Add_Click({
|
$okButton.Add_Click({
|
||||||
|
$masterPassword = $masterPasswordTextBox.Text # Masterkennwort holen
|
||||||
foreach ($row in $dataGridView.Rows) {
|
foreach ($row in $dataGridView.Rows) {
|
||||||
if ($row.Index -lt $dataGridView.RowCount - 1) { # Nicht für die leere letzte Zeile
|
if ($row.Index -lt $dataGridView.RowCount - 1) { # Nicht für die leere letzte Zeile
|
||||||
$title = $row.Cells[0].Value
|
$title = $row.Cells[0].Value
|
||||||
@@ -133,6 +174,16 @@ function Create-User {
|
|||||||
$password = $row.Cells[4].Value
|
$password = $row.Cells[4].Value
|
||||||
$ou = $row.Cells[5].Value # Hier wird die ausgewählte OU aus der ComboBox abgerufen
|
$ou = $row.Cells[5].Value # Hier wird die ausgewählte OU aus der ComboBox abgerufen
|
||||||
|
|
||||||
|
# Wenn keine OU in der Zeile gewählt wurde, nehme die Master-OU
|
||||||
|
if (-not $ou) {
|
||||||
|
$ou = $masterOUComboBox.SelectedItem
|
||||||
|
}
|
||||||
|
|
||||||
|
# Wenn kein Passwort angegeben wurde, nutze das Masterkennwort
|
||||||
|
if (-not $password) {
|
||||||
|
$password = $masterPassword
|
||||||
|
}
|
||||||
|
|
||||||
# Überprüfen, ob notwendige Felder ausgefüllt sind
|
# Überprüfen, ob notwendige Felder ausgefüllt sind
|
||||||
if (-not $firstName -or -not $lastName) {
|
if (-not $firstName -or -not $lastName) {
|
||||||
$missingField = if (-not $firstName) { "Vorname" } elseif (-not $lastName) { "Nachname" }
|
$missingField = if (-not $firstName) { "Vorname" } elseif (-not $lastName) { "Nachname" }
|
||||||
@@ -143,19 +194,8 @@ function Create-User {
|
|||||||
# Benutzername generieren: erster Buchstabe des Vornamens + Nachname
|
# Benutzername generieren: erster Buchstabe des Vornamens + Nachname
|
||||||
$username = ($firstName.Substring(0, 1) + $lastName).ToLower()
|
$username = ($firstName.Substring(0, 1) + $lastName).ToLower()
|
||||||
|
|
||||||
# Passwort prüfen
|
|
||||||
if (-not $password) {
|
|
||||||
$outputTextBox.AppendText("Fehler bei der Erstellung des Benutzers '$firstName $lastName': Passwort fehlt.`r`n")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
# E-Mail-Adresse generieren
|
# E-Mail-Adresse generieren
|
||||||
$email = Get-EmailAddress -firstName $firstName -lastName $lastName
|
$email = Get-EmailAddress -username $username
|
||||||
|
|
||||||
# Master-OU für den Benutzer setzen, falls keine OU explizit ausgewählt wurde
|
|
||||||
if (-not $ou) {
|
|
||||||
$ou = $masterOUComboBox.SelectedItem
|
|
||||||
}
|
|
||||||
|
|
||||||
# Benutzer erstellen
|
# Benutzer erstellen
|
||||||
try {
|
try {
|
||||||
@@ -163,22 +203,27 @@ function Create-User {
|
|||||||
$user = Get-ADUser -Filter { SamAccountName -eq $username }
|
$user = Get-ADUser -Filter { SamAccountName -eq $username }
|
||||||
if (-not $user) {
|
if (-not $user) {
|
||||||
# Benutzer erstellen, falls er nicht existiert
|
# Benutzer erstellen, falls er nicht existiert
|
||||||
New-ADUser -Name "$firstName $lastName"
|
try {
|
||||||
-GivenName $firstName
|
New-ADUser -Name "$firstName $lastName" `
|
||||||
-Surname $lastName
|
-GivenName "$firstName" `
|
||||||
-SamAccountName $username
|
-Surname "$lastName" `
|
||||||
-UserPrincipalName $email
|
-SamAccountName "$username" `
|
||||||
-EmailAddress $email
|
-UserPrincipalName "$email" `
|
||||||
-AccountPassword (ConvertTo-SecureString $password -AsPlainText -Force)
|
-AccountPassword (ConvertTo-SecureString $password -AsPlainText -Force) `
|
||||||
-Enabled $true
|
-Enabled $true `
|
||||||
-Path $ou
|
-Path "$ou"
|
||||||
|
|
||||||
# Erfolgsnachricht für Benutzererstellung in grün
|
|
||||||
$outputTextBox.SelectionColor = 'Green'
|
$outputTextBox.SelectionColor = 'Green'
|
||||||
$outputTextBox.AppendText("Benutzer $username wurde erfolgreich erstellt.`r`n")
|
$outputTextBox.AppendText("Benutzer $username wurde erfolgreich erstellt.`r`n")
|
||||||
}
|
}
|
||||||
|
catch {
|
||||||
|
$outputTextBox.SelectionColor = 'Red'
|
||||||
|
$outputTextBox.AppendText("Fehler bei der Erstellung des Benutzers '$firstName $lastName': $_.Exception.Message`r`n")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
# Erfolgsnachricht für vorhandenen Benutzer in grün
|
# Erfolgsnachricht für vorhandenen Benutzer
|
||||||
$outputTextBox.SelectionColor = 'Green'
|
$outputTextBox.SelectionColor = 'Green'
|
||||||
$outputTextBox.AppendText("Benutzer $username existiert bereits.`r`n")
|
$outputTextBox.AppendText("Benutzer $username existiert bereits.`r`n")
|
||||||
}
|
}
|
||||||
@@ -188,30 +233,34 @@ function Create-User {
|
|||||||
# Gruppen-OU immer auf die Master-OU setzen
|
# Gruppen-OU immer auf die Master-OU setzen
|
||||||
$groupOU = $masterGroupOU
|
$groupOU = $masterGroupOU
|
||||||
try {
|
try {
|
||||||
# Überprüfen, ob die Gruppe existiert, und gegebenenfalls erstellen
|
# Überprüfen, ob die Gruppe existiert
|
||||||
$group = Get-ADGroup -Filter { Name -eq $globalGroup }
|
$group = Get-ADGroup -Filter { Name -eq $globalGroup }
|
||||||
if (-not $group) {
|
try {
|
||||||
# Gruppe erstellen, falls sie nicht existiert
|
# Gruppe erstellen, falls sie nicht existiert
|
||||||
New-ADGroup -Name $globalGroup
|
$groupName = "GG_" + $globalGroup
|
||||||
-GroupScope Global
|
New-ADGroup -Name $groupName `
|
||||||
-Path $groupOU
|
-GroupScope Global `
|
||||||
-Description "Globale Gruppe für $globalGroup"
|
-Path $groupOU `
|
||||||
|
-Description "Globale Gruppe für $groupName" `
|
||||||
# Erfolgsnachricht für Gruppenerstellung
|
-Enabled $true
|
||||||
|
# Erfolgsnachricht
|
||||||
$outputTextBox.SelectionColor = 'Green'
|
$outputTextBox.SelectionColor = 'Green'
|
||||||
$outputTextBox.AppendText("Globale Gruppe '$globalGroup' wurde erfolgreich erstellt.`r`n")
|
$outputTextBox.AppendText("Globale Gruppe '$groupName' wurde erfolgreich erstellt.`r`n")
|
||||||
}
|
}
|
||||||
# Benutzer der Gruppe zuordnen
|
catch {
|
||||||
Add-ADGroupMember -Identity $globalGroup -Members $username
|
$outputTextBox.SelectionColor = 'Red'
|
||||||
$outputTextBox.SelectionColor = 'Green'
|
$outputTextBox.AppendText("Fehler bei der Erstellung der Gruppe '$groupName': $_.Exception.Message`r`n")
|
||||||
$outputTextBox.AppendText("Benutzer '$username' wurde erfolgreich der Gruppe '$globalGroup' zugeordnet.`r`n")
|
$outputTextBox.AppendText("Fehlerdetails: $_`r`n")
|
||||||
} catch {
|
}
|
||||||
# Fehler bei der Gruppenzuordnung in rot
|
}
|
||||||
|
catch {
|
||||||
|
# Fehler bei der Gruppenzuordnung
|
||||||
$outputTextBox.SelectionColor = 'Red'
|
$outputTextBox.SelectionColor = 'Red'
|
||||||
$outputTextBox.AppendText("Fehler bei der Gruppenzuordnung für Benutzer '$username': $_.Exception.Message`r`n")
|
$outputTextBox.AppendText("Fehler bei der Gruppenzuordnung für Benutzer '$username': $_.Exception.Message`r`n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
}
|
||||||
|
catch {
|
||||||
# Fehler bei der Benutzererstellung
|
# Fehler bei der Benutzererstellung
|
||||||
$outputTextBox.SelectionColor = 'Red'
|
$outputTextBox.SelectionColor = 'Red'
|
||||||
$outputTextBox.AppendText("Fehler bei der Erstellung des Benutzers '$firstName $lastName': $_.Exception.Message`r`n")
|
$outputTextBox.AppendText("Fehler bei der Erstellung des Benutzers '$firstName $lastName': $_.Exception.Message`r`n")
|
||||||
@@ -220,26 +269,18 @@ function Create-User {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
# Beenden-Button erstellen
|
# Event-Handler für den Beenden-Button hinzufügen
|
||||||
$exitButton = New-Object System.Windows.Forms.Button
|
|
||||||
$exitButton.Text = "Beenden"
|
|
||||||
$exitButton.Size = New-Object System.Drawing.Size(380, 30) # Größe des Buttons festgelegt
|
|
||||||
$exitButton.Location = New-Object System.Drawing.Point(395, 510) # Position des Beenden-Buttons
|
|
||||||
$exitButton.Add_Click({
|
$exitButton.Add_Click({
|
||||||
$form.Close() # Formular schließen
|
$form.Close() # Formular schließen
|
||||||
})
|
})
|
||||||
|
|
||||||
# Buttons zum Formular hinzufügen
|
|
||||||
$form.Controls.Add($okButton)
|
|
||||||
$form.Controls.Add($exitButton)
|
|
||||||
|
|
||||||
# Funktion zum Erstellen der E-Mail-Adresse
|
# Funktion zum Erstellen der E-Mail-Adresse
|
||||||
function Get-EmailAddress {
|
function Get-EmailAddress {
|
||||||
param (
|
param (
|
||||||
[string]$firstName,
|
[string]$username
|
||||||
[string]$lastName
|
|
||||||
)
|
)
|
||||||
return "$firstName.$lastName@$domain"
|
|
||||||
|
return "$username@$domain"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Formular anzeigen
|
# Formular anzeigen
|
||||||
@@ -249,72 +290,72 @@ function Create-User {
|
|||||||
# Funktion, die beim Klick auf "Create Groups" ausgeführt wird
|
# Funktion, die beim Klick auf "Create Groups" ausgeführt wird
|
||||||
function Create-Groups {
|
function Create-Groups {
|
||||||
Write-Host "Erstelle Gruppen..."
|
Write-Host "Erstelle Gruppen..."
|
||||||
Add-Type -AssemblyName System.Windows.Forms
|
Add-Type -AssemblyName System.Windows.Forms
|
||||||
Import-Module ActiveDirectory
|
Import-Module ActiveDirectory
|
||||||
|
|
||||||
# Holen Sie sich die Domäne aus dem Active Directory
|
# Holen Sie sich die Domäne aus dem Active Directory
|
||||||
$domain = (Get-ADDomain).DNSRoot
|
$domain = (Get-ADDomain).DNSRoot
|
||||||
|
|
||||||
# GUI erstellen
|
# GUI erstellen
|
||||||
$form = New-Object System.Windows.Forms.Form
|
$form = New-Object System.Windows.Forms.Form
|
||||||
$form.Text = "Gruppen Erstellung"
|
$form.Text = "Gruppen Erstellung"
|
||||||
$form.Size = New-Object System.Drawing.Size(600, 555) # Gesamtgröße der Form anpassen
|
$form.Size = New-Object System.Drawing.Size(600, 555) # Gesamtgröße der Form anpassen
|
||||||
|
|
||||||
# DataGridView für Gruppen erstellen
|
# DataGridView für Gruppen erstellen
|
||||||
$dataGridView = New-Object System.Windows.Forms.DataGridView
|
$dataGridView = New-Object System.Windows.Forms.DataGridView
|
||||||
$dataGridView.Size = New-Object System.Drawing.Size(564, 300) # Breite und Höhe des DataGridViews
|
$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
|
$dataGridView.Location = New-Object System.Drawing.Point(10, 10) # Position des DataGridViews
|
||||||
$form.Controls.Add($dataGridView)
|
$form.Controls.Add($dataGridView)
|
||||||
|
|
||||||
# Definieren der Spalten für die DataGridView
|
# Definieren der Spalten für die DataGridView
|
||||||
$dataGridView.ColumnCount = 3
|
$dataGridView.ColumnCount = 3
|
||||||
$dataGridView.Columns[0].Name = "Typ" # Typ in der ersten Spalte
|
$dataGridView.Columns[0].Name = "Typ" # Typ in der ersten Spalte
|
||||||
$dataGridView.Columns[1].Name = "Gruppenname" # Gruppenname in der zweiten Spalte
|
$dataGridView.Columns[1].Name = "Gruppenname" # Gruppenname in der zweiten Spalte
|
||||||
$dataGridView.Columns[2].Name = "OU" # OU in der dritten Spalte
|
$dataGridView.Columns[2].Name = "OU" # OU in der dritten Spalte
|
||||||
|
|
||||||
# Breite der Spalten festlegen
|
# Breite der Spalten festlegen
|
||||||
$dataGridView.Columns[0].Width = 75 # Typ-Spalte auf 50 Pixel setzen
|
$dataGridView.Columns[0].Width = 75 # Typ-Spalte auf 50 Pixel setzen
|
||||||
$dataGridView.Columns[1].Width = 100 # Gruppenname-Spalte auf 100 Pixel setzen
|
$dataGridView.Columns[1].Width = 100 # Gruppenname-Spalte auf 100 Pixel setzen
|
||||||
$dataGridView.Columns[2].Width = 345 # OU-Spalte auf 400 Pixel setzen
|
$dataGridView.Columns[2].Width = 345 # OU-Spalte auf 400 Pixel setzen
|
||||||
|
|
||||||
# Dropdown für den Typ (GG oder DL)
|
# Dropdown für den Typ (GG oder DL)
|
||||||
$typColumn = New-Object System.Windows.Forms.DataGridViewComboBoxColumn
|
$typColumn = New-Object System.Windows.Forms.DataGridViewComboBoxColumn
|
||||||
$typColumn.HeaderText = "Typ"
|
$typColumn.HeaderText = "Typ"
|
||||||
$typColumn.Items.Add("GG")
|
$typColumn.Items.Add("GG")
|
||||||
$typColumn.Items.Add("DL")
|
$typColumn.Items.Add("DL")
|
||||||
$typColumn.Items.Add("DL_OS")
|
$typColumn.Items.Add("DL_OS")
|
||||||
$dataGridView.Columns.RemoveAt(0)
|
$dataGridView.Columns.RemoveAt(0)
|
||||||
$dataGridView.Columns.Insert(0, $typColumn)
|
$dataGridView.Columns.Insert(0, $typColumn)
|
||||||
# Breite der Typ-Spalte setzen
|
# Breite der Typ-Spalte setzen
|
||||||
$typColumn.Width = 75 # Du kannst hier den Wert nach Bedarf anpassen
|
$typColumn.Width = 75 # Du kannst hier den Wert nach Bedarf anpassen
|
||||||
|
|
||||||
# Dropdown für die OU-Auswahl in der dritten Spalte
|
# Dropdown für die OU-Auswahl in der dritten Spalte
|
||||||
$ouColumn = New-Object System.Windows.Forms.DataGridViewComboBoxColumn
|
$ouColumn = New-Object System.Windows.Forms.DataGridViewComboBoxColumn
|
||||||
$ouColumn.HeaderText = "OU"
|
$ouColumn.HeaderText = "OU"
|
||||||
$groupOUList = Get-ADOrganizationalUnit -Filter * | Select-Object -ExpandProperty DistinguishedName
|
$groupOUList = Get-ADOrganizationalUnit -Filter * | Select-Object -ExpandProperty DistinguishedName
|
||||||
foreach ($ou in $groupOUList) {
|
foreach ($ou in $groupOUList) {
|
||||||
$ouColumn.Items.Add($ou)
|
$ouColumn.Items.Add($ou)
|
||||||
}
|
}
|
||||||
$dataGridView.Columns.RemoveAt(2)
|
$dataGridView.Columns.RemoveAt(2)
|
||||||
$dataGridView.Columns.Insert(2, $ouColumn)
|
$dataGridView.Columns.Insert(2, $ouColumn)
|
||||||
|
|
||||||
# Breite der OU-Spalte setzen
|
# Breite der OU-Spalte setzen
|
||||||
$ouColumn.Width = 345 # Du kannst hier den Wert nach Bedarf anpassen
|
$ouColumn.Width = 345 # Du kannst hier den Wert nach Bedarf anpassen
|
||||||
|
|
||||||
# RichTextBox für Ausgaben
|
# RichTextBox für Ausgaben
|
||||||
$outputTextBox = New-Object System.Windows.Forms.RichTextBox
|
$outputTextBox = New-Object System.Windows.Forms.RichTextBox
|
||||||
$outputTextBox.Multiline = $true
|
$outputTextBox.Multiline = $true
|
||||||
$outputTextBox.Location = New-Object System.Drawing.Point(10, 320) # Position unterhalb des DataGridViews
|
$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.Size = New-Object System.Drawing.Size(564, 150) # Größe der RichTextBox
|
||||||
$outputTextBox.ScrollBars = 'Vertical'
|
$outputTextBox.ScrollBars = 'Vertical'
|
||||||
$form.Controls.Add($outputTextBox)
|
$form.Controls.Add($outputTextBox)
|
||||||
|
|
||||||
# OK-Button für Gruppen erstellen
|
# OK-Button für Gruppen erstellen
|
||||||
$okButton = New-Object System.Windows.Forms.Button
|
$okButton = New-Object System.Windows.Forms.Button
|
||||||
$okButton.Text = "Gruppen erstellen"
|
$okButton.Text = "Gruppen erstellen"
|
||||||
$okButton.Size = New-Object System.Drawing.Size(280, 30) # Größe des Buttons
|
$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.Location = New-Object System.Drawing.Point(10, 475) # Position des Buttons
|
||||||
$okButton.Add_Click({
|
$okButton.Add_Click({
|
||||||
foreach ($row in $dataGridView.Rows) {
|
foreach ($row in $dataGridView.Rows) {
|
||||||
if ($row.Index -lt $dataGridView.RowCount - 1) { # Nicht für die leere letzte Zeile
|
if ($row.Index -lt $dataGridView.RowCount - 1) { # Nicht für die leere letzte Zeile
|
||||||
$groupType = $row.Cells[0].Value
|
$groupType = $row.Cells[0].Value
|
||||||
@@ -323,7 +364,7 @@ $okButton.Add_Click({
|
|||||||
|
|
||||||
if (-not $groupType -or -not $groupName -or -not $groupOU) {
|
if (-not $groupType -or -not $groupName -or -not $groupOU) {
|
||||||
$outputTextBox.SelectionColor = 'Red'
|
$outputTextBox.SelectionColor = 'Red'
|
||||||
$outputTextBox.AppendText("Fehler: Alle Felder (Typ, Gruppenname, OU) müssen ausgefüllt sein.`r`n")
|
$outputTextBox.AppendText("Fehler: Alle Felder (Typ, Gruppenname, OU) müssen ausgefüllt sein.`r`n")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,7 +385,7 @@ $okButton.Add_Click({
|
|||||||
New-ADGroup -Name $groupName `
|
New-ADGroup -Name $groupName `
|
||||||
-GroupScope Global `
|
-GroupScope Global `
|
||||||
-Path $groupOU `
|
-Path $groupOU `
|
||||||
-Description "Globale Gruppe für $groupName"
|
-Description "Globale Gruppe für $groupName"
|
||||||
$outputTextBox.SelectionColor = 'Green'
|
$outputTextBox.SelectionColor = 'Green'
|
||||||
$outputTextBox.AppendText("Globale Gruppe '$groupName' wurde erfolgreich erstellt.`r`n")
|
$outputTextBox.AppendText("Globale Gruppe '$groupName' wurde erfolgreich erstellt.`r`n")
|
||||||
} else {
|
} else {
|
||||||
@@ -358,7 +399,7 @@ $okButton.Add_Click({
|
|||||||
New-ADGroup -Name $domainLocalGroupName `
|
New-ADGroup -Name $domainLocalGroupName `
|
||||||
-GroupScope DomainLocal `
|
-GroupScope DomainLocal `
|
||||||
-Path $groupOU `
|
-Path $groupOU `
|
||||||
-Description "DomainLocal Gruppe für $domainLocalGroupName"
|
-Description "DomainLocal Gruppe für $domainLocalGroupName"
|
||||||
$outputTextBox.SelectionColor = 'Green'
|
$outputTextBox.SelectionColor = 'Green'
|
||||||
$outputTextBox.AppendText("DomainLocal Gruppe '$domainLocalGroupName' wurde erfolgreich erstellt.`r`n")
|
$outputTextBox.AppendText("DomainLocal Gruppe '$domainLocalGroupName' wurde erfolgreich erstellt.`r`n")
|
||||||
} else {
|
} else {
|
||||||
@@ -375,7 +416,7 @@ $okButton.Add_Click({
|
|||||||
New-ADGroup -Name $domainLocalGroupName `
|
New-ADGroup -Name $domainLocalGroupName `
|
||||||
-GroupScope DomainLocal `
|
-GroupScope DomainLocal `
|
||||||
-Path $groupOU `
|
-Path $groupOU `
|
||||||
-Description "DomainLocal Gruppe für $domainLocalGroupName"
|
-Description "DomainLocal Gruppe für $domainLocalGroupName"
|
||||||
$outputTextBox.SelectionColor = 'Green'
|
$outputTextBox.SelectionColor = 'Green'
|
||||||
$outputTextBox.AppendText("DomainLocal Gruppe '$domainLocalGroupName' wurde erfolgreich erstellt.`r`n")
|
$outputTextBox.AppendText("DomainLocal Gruppe '$domainLocalGroupName' wurde erfolgreich erstellt.`r`n")
|
||||||
} else {
|
} else {
|
||||||
@@ -391,144 +432,144 @@ $okButton.Add_Click({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
# Beenden-Button erstellen
|
# Beenden-Button erstellen
|
||||||
$exitButton = New-Object System.Windows.Forms.Button
|
$exitButton = New-Object System.Windows.Forms.Button
|
||||||
$exitButton.Text = "Beenden"
|
$exitButton.Text = "Beenden"
|
||||||
$exitButton.Size = New-Object System.Drawing.Size(280, 30)
|
$exitButton.Size = New-Object System.Drawing.Size(280, 30)
|
||||||
$exitButton.Location = New-Object System.Drawing.Point(295, 475) # Position des Beenden-Buttons
|
$exitButton.Location = New-Object System.Drawing.Point(295, 475) # Position des Beenden-Buttons
|
||||||
$exitButton.Add_Click({
|
$exitButton.Add_Click({
|
||||||
$form.Close() # Formular schließen
|
$form.Close() # Formular schließen
|
||||||
})
|
})
|
||||||
|
|
||||||
# Buttons zum Formular hinzufügen
|
# Buttons zum Formular hinzufügen
|
||||||
$form.Controls.Add($okButton)
|
$form.Controls.Add($okButton)
|
||||||
$form.Controls.Add($exitButton)
|
$form.Controls.Add($exitButton)
|
||||||
|
|
||||||
# Formular anzeigen
|
# Formular anzeigen
|
||||||
$form.ShowDialog()
|
$form.ShowDialog()
|
||||||
}
|
}
|
||||||
|
|
||||||
# Funktion, die beim Klick auf "ADGDL" ausgeführt wird
|
# Funktion, die beim Klick auf "ADGDL" ausgeführt wird
|
||||||
function ADGDL {
|
function ADGDL {
|
||||||
Write-Host "Führe ADGDL aus..."
|
Write-Host "Führe AGDLP aus..."
|
||||||
Add-Type -AssemblyName System.Windows.Forms
|
Add-Type -AssemblyName System.Windows.Forms
|
||||||
Import-Module ActiveDirectory
|
Import-Module ActiveDirectory
|
||||||
|
|
||||||
# Funktion zum Abrufen der aktuellen Domäne
|
# Funktion zum Abrufen der aktuellen Domäne
|
||||||
function Get-DomainName {
|
function Get-DomainName {
|
||||||
$domain = (Get-ADDomain).DNSRoot
|
$domain = (Get-ADDomain).DNSRoot
|
||||||
return $domain
|
return $domain
|
||||||
}
|
}
|
||||||
|
|
||||||
# Funktion zum Abrufen von Gruppen aus AD
|
# Funktion zum Abrufen von Gruppen aus AD
|
||||||
function Get-Groups {
|
function Get-Groups {
|
||||||
$groups = Get-ADGroup -Filter *
|
$groups = Get-ADGroup -Filter *
|
||||||
return $groups | ForEach-Object { $_.Name }
|
return $groups | ForEach-Object { $_.Name }
|
||||||
}
|
}
|
||||||
|
|
||||||
# Funktion zum Abrufen von Benutzern aus AD
|
# Funktion zum Abrufen von Benutzern aus AD
|
||||||
function Get-Users {
|
function Get-Users {
|
||||||
$users = Get-ADUser -Filter *
|
$users = Get-ADUser -Filter *
|
||||||
return $users | ForEach-Object { $_.SamAccountName }
|
return $users | ForEach-Object { $_.SamAccountName }
|
||||||
}
|
}
|
||||||
|
|
||||||
$domain = Get-DomainName
|
$domain = Get-DomainName
|
||||||
$ggList = Get-ADGroup -Filter { GroupScope -eq 'Global' }
|
$ggList = Get-ADGroup -Filter { GroupScope -eq 'Global' }
|
||||||
$ggList = $ggList | Select-Object -ExpandProperty Name
|
$ggList = $ggList | Select-Object -ExpandProperty Name
|
||||||
$dlList = Get-Groups
|
$dlList = Get-Groups
|
||||||
$userList = Get-Users
|
$userList = Get-Users
|
||||||
|
|
||||||
# GUI zur Zuordnung von GG zu DL und Benutzern erstellen
|
# GUI zur Zuordnung von GG zu DL und Benutzern erstellen
|
||||||
$form = New-Object System.Windows.Forms.Form
|
$form = New-Object System.Windows.Forms.Form
|
||||||
$form.Text = "GG zu DL Zuordnung und Benutzer"
|
$form.Text = "GG zu DL Zuordnung und Benutzer"
|
||||||
$form.Size = New-Object System.Drawing.Size(805, 435) # Fenstergröße anpassen
|
$form.Size = New-Object System.Drawing.Size(805, 435) # Fenstergröße anpassen
|
||||||
|
|
||||||
# Benutzer-Eingabe und Liste (ganz oben)
|
# Benutzer-Eingabe und Liste (ganz oben)
|
||||||
$userLabel = New-Object System.Windows.Forms.Label
|
$userLabel = New-Object System.Windows.Forms.Label
|
||||||
$userLabel.Text = "Benutzer zu Globalgruppe zuordnen:"
|
$userLabel.Text = "Benutzer zu Globalgruppe zuordnen:"
|
||||||
$userLabel.Location = New-Object System.Drawing.Point(10, 10)
|
$userLabel.Location = New-Object System.Drawing.Point(10, 10)
|
||||||
$userLabel.Size = New-Object System.Drawing.Size(250, 20)
|
$userLabel.Size = New-Object System.Drawing.Size(250, 20)
|
||||||
$form.Controls.Add($userLabel)
|
$form.Controls.Add($userLabel)
|
||||||
|
|
||||||
$userTextBox = New-Object System.Windows.Forms.TextBox
|
$userTextBox = New-Object System.Windows.Forms.TextBox
|
||||||
$userTextBox.Location = New-Object System.Drawing.Point(10, 30)
|
$userTextBox.Location = New-Object System.Drawing.Point(10, 30)
|
||||||
$userTextBox.Size = New-Object System.Drawing.Size(250, 20)
|
$userTextBox.Size = New-Object System.Drawing.Size(250, 20)
|
||||||
$form.Controls.Add($userTextBox)
|
$form.Controls.Add($userTextBox)
|
||||||
|
|
||||||
$userListBox = New-Object System.Windows.Forms.ListBox
|
$userListBox = New-Object System.Windows.Forms.ListBox
|
||||||
$userListBox.Location = New-Object System.Drawing.Point(10, 55)
|
$userListBox.Location = New-Object System.Drawing.Point(10, 55)
|
||||||
$userListBox.Size = New-Object System.Drawing.Size(250, 200) # Anpassung der Größe
|
$userListBox.Size = New-Object System.Drawing.Size(250, 200) # Anpassung der Größe
|
||||||
$userListBox.Items.AddRange($userList)
|
$userListBox.Items.AddRange($userList)
|
||||||
$userListBox.SelectionMode = [System.Windows.Forms.SelectionMode]::MultiExtended
|
$userListBox.SelectionMode = [System.Windows.Forms.SelectionMode]::MultiExtended
|
||||||
$form.Controls.Add($userListBox)
|
$form.Controls.Add($userListBox)
|
||||||
|
|
||||||
$userTextBox.Add_TextChanged({
|
$userTextBox.Add_TextChanged({
|
||||||
$userListBox.Items.Clear()
|
$userListBox.Items.Clear()
|
||||||
$filteredUsers = $userList | Where-Object { $_ -like "*$($userTextBox.Text)*" }
|
$filteredUsers = $userList | Where-Object { $_ -like "*$($userTextBox.Text)*" }
|
||||||
$userListBox.Items.AddRange($filteredUsers)
|
$userListBox.Items.AddRange($filteredUsers)
|
||||||
})
|
})
|
||||||
|
|
||||||
# GG-Eingabe und Liste (mitte)
|
# GG-Eingabe und Liste (mitte)
|
||||||
$ggLabel = New-Object System.Windows.Forms.Label
|
$ggLabel = New-Object System.Windows.Forms.Label
|
||||||
$ggLabel.Text = "Globalgruppe (GG):"
|
$ggLabel.Text = "Globalgruppe (GG):"
|
||||||
$ggLabel.Location = New-Object System.Drawing.Point(270, 10)
|
$ggLabel.Location = New-Object System.Drawing.Point(270, 10)
|
||||||
$ggLabel.Size = New-Object System.Drawing.Size(250, 20)
|
$ggLabel.Size = New-Object System.Drawing.Size(250, 20)
|
||||||
$form.Controls.Add($ggLabel)
|
$form.Controls.Add($ggLabel)
|
||||||
|
|
||||||
$ggTextBox = New-Object System.Windows.Forms.TextBox
|
$ggTextBox = New-Object System.Windows.Forms.TextBox
|
||||||
$ggTextBox.Location = New-Object System.Drawing.Point(270, 30)
|
$ggTextBox.Location = New-Object System.Drawing.Point(270, 30)
|
||||||
$ggTextBox.Size = New-Object System.Drawing.Size(250, 20)
|
$ggTextBox.Size = New-Object System.Drawing.Size(250, 20)
|
||||||
$form.Controls.Add($ggTextBox)
|
$form.Controls.Add($ggTextBox)
|
||||||
|
|
||||||
$ggListBox = New-Object System.Windows.Forms.ListBox
|
$ggListBox = New-Object System.Windows.Forms.ListBox
|
||||||
$ggListBox.Location = New-Object System.Drawing.Point(270, 55)
|
$ggListBox.Location = New-Object System.Drawing.Point(270, 55)
|
||||||
$ggListBox.Size = New-Object System.Drawing.Size(250, 200)
|
$ggListBox.Size = New-Object System.Drawing.Size(250, 200)
|
||||||
$ggListBox.Items.AddRange($ggList)
|
$ggListBox.Items.AddRange($ggList)
|
||||||
$ggListBox.SelectionMode = [System.Windows.Forms.SelectionMode]::One
|
$ggListBox.SelectionMode = [System.Windows.Forms.SelectionMode]::One
|
||||||
$form.Controls.Add($ggListBox)
|
$form.Controls.Add($ggListBox)
|
||||||
|
|
||||||
$ggTextBox.Add_TextChanged({
|
$ggTextBox.Add_TextChanged({
|
||||||
$ggListBox.Items.Clear()
|
$ggListBox.Items.Clear()
|
||||||
$filteredGGs = $ggList | Where-Object { $_ -like "*$($ggTextBox.Text)*" }
|
$filteredGGs = $ggList | Where-Object { $_ -like "*$($ggTextBox.Text)*" }
|
||||||
$ggListBox.Items.AddRange($filteredGGs)
|
$ggListBox.Items.AddRange($filteredGGs)
|
||||||
})
|
})
|
||||||
|
|
||||||
# DL-Eingabe und Liste (ganz unten)
|
# DL-Eingabe und Liste (ganz unten)
|
||||||
$dlLabel = New-Object System.Windows.Forms.Label
|
$dlLabel = New-Object System.Windows.Forms.Label
|
||||||
$dlLabel.Text = "Domänenlokale Gruppen (DL):"
|
$dlLabel.Text = "Domänenlokale Gruppen (DL):"
|
||||||
$dlLabel.Location = New-Object System.Drawing.Point(530, 10)
|
$dlLabel.Location = New-Object System.Drawing.Point(530, 10)
|
||||||
$dlLabel.Size = New-Object System.Drawing.Size(250, 20)
|
$dlLabel.Size = New-Object System.Drawing.Size(250, 20)
|
||||||
$form.Controls.Add($dlLabel)
|
$form.Controls.Add($dlLabel)
|
||||||
|
|
||||||
$dlTextBox = New-Object System.Windows.Forms.TextBox
|
$dlTextBox = New-Object System.Windows.Forms.TextBox
|
||||||
$dlTextBox.Location = New-Object System.Drawing.Point(530, 30)
|
$dlTextBox.Location = New-Object System.Drawing.Point(530, 30)
|
||||||
$dlTextBox.Size = New-Object System.Drawing.Size(250, 20)
|
$dlTextBox.Size = New-Object System.Drawing.Size(250, 20)
|
||||||
$form.Controls.Add($dlTextBox)
|
$form.Controls.Add($dlTextBox)
|
||||||
|
|
||||||
$dlListBox = New-Object System.Windows.Forms.ListBox
|
$dlListBox = New-Object System.Windows.Forms.ListBox
|
||||||
$dlListBox.Location = New-Object System.Drawing.Point(530, 55)
|
$dlListBox.Location = New-Object System.Drawing.Point(530, 55)
|
||||||
$dlListBox.Size = New-Object System.Drawing.Size(250, 200)
|
$dlListBox.Size = New-Object System.Drawing.Size(250, 200)
|
||||||
$dlListBox.Items.AddRange($dlList)
|
$dlListBox.Items.AddRange($dlList)
|
||||||
$dlListBox.SelectionMode = [System.Windows.Forms.SelectionMode]::MultiExtended
|
$dlListBox.SelectionMode = [System.Windows.Forms.SelectionMode]::MultiExtended
|
||||||
$form.Controls.Add($dlListBox)
|
$form.Controls.Add($dlListBox)
|
||||||
|
|
||||||
$dlTextBox.Add_TextChanged({
|
$dlTextBox.Add_TextChanged({
|
||||||
$dlListBox.Items.Clear()
|
$dlListBox.Items.Clear()
|
||||||
$filteredDLs = $dlList | Where-Object { $_ -like "*$($dlTextBox.Text)*" }
|
$filteredDLs = $dlList | Where-Object { $_ -like "*$($dlTextBox.Text)*" }
|
||||||
$dlListBox.Items.AddRange($filteredDLs)
|
$dlListBox.Items.AddRange($filteredDLs)
|
||||||
})
|
})
|
||||||
|
|
||||||
# RichTextBox für Debug-Informationen hinzufügen
|
# RichTextBox für Debug-Informationen hinzufügen
|
||||||
$debugTextBox = New-Object System.Windows.Forms.RichTextBox
|
$debugTextBox = New-Object System.Windows.Forms.RichTextBox
|
||||||
$debugTextBox.Location = New-Object System.Drawing.Point(10, 265)
|
$debugTextBox.Location = New-Object System.Drawing.Point(10, 265)
|
||||||
$debugTextBox.Size = New-Object System.Drawing.Size(770, 80)
|
$debugTextBox.Size = New-Object System.Drawing.Size(770, 80)
|
||||||
$debugTextBox.ReadOnly = $true
|
$debugTextBox.ReadOnly = $true
|
||||||
$form.Controls.Add($debugTextBox)
|
$form.Controls.Add($debugTextBox)
|
||||||
|
|
||||||
# Methode zur Ausgabe von Nachrichten im RichTextBox
|
# Methode zur Ausgabe von Nachrichten im RichTextBox
|
||||||
function Add-DebugMessage {
|
function Add-DebugMessage {
|
||||||
param (
|
param (
|
||||||
[string]$message,
|
[string]$message,
|
||||||
[string]$color
|
[string]$color
|
||||||
@@ -538,14 +579,14 @@ function Add-DebugMessage {
|
|||||||
$debugTextBox.SelectionLength = 0
|
$debugTextBox.SelectionLength = 0
|
||||||
$debugTextBox.SelectionColor = $color
|
$debugTextBox.SelectionColor = $color
|
||||||
$debugTextBox.AppendText("$message`r`n")
|
$debugTextBox.AppendText("$message`r`n")
|
||||||
}
|
}
|
||||||
|
|
||||||
# OK-Button
|
# OK-Button
|
||||||
$okButton = New-Object System.Windows.Forms.Button
|
$okButton = New-Object System.Windows.Forms.Button
|
||||||
$okButton.Text = "OK"
|
$okButton.Text = "OK"
|
||||||
$okButton.Location = New-Object System.Drawing.Point(10, 355)
|
$okButton.Location = New-Object System.Drawing.Point(10, 355)
|
||||||
$okButton.Size = New-Object System.Drawing.Size(380, 30)
|
$okButton.Size = New-Object System.Drawing.Size(380, 30)
|
||||||
$okButton.Add_Click({
|
$okButton.Add_Click({
|
||||||
$gg = $ggListBox.SelectedItem
|
$gg = $ggListBox.SelectedItem
|
||||||
$dl = $dlListBox.SelectedItems
|
$dl = $dlListBox.SelectedItems
|
||||||
$users = $userListBox.SelectedItems
|
$users = $userListBox.SelectedItems
|
||||||
@@ -554,7 +595,7 @@ $okButton.Add_Click({
|
|||||||
foreach ($user in $users) {
|
foreach ($user in $users) {
|
||||||
if (-not (Get-ADGroupMember -Identity $gg -Recursive | Where-Object { $_.SamAccountName -eq $user })) {
|
if (-not (Get-ADGroupMember -Identity $gg -Recursive | Where-Object { $_.SamAccountName -eq $user })) {
|
||||||
Add-ADGroupMember -Identity $gg -Members $user
|
Add-ADGroupMember -Identity $gg -Members $user
|
||||||
Add-DebugMessage "Benutzer $user wurde der Globalgruppe $gg hinzugefügt." "Green"
|
Add-DebugMessage "Benutzer $user wurde der Globalgruppe $gg hinzugefügt." "Green"
|
||||||
} else {
|
} else {
|
||||||
Add-DebugMessage "Benutzer $user ist bereits Mitglied der Globalgruppe $gg." "Orange"
|
Add-DebugMessage "Benutzer $user ist bereits Mitglied der Globalgruppe $gg." "Orange"
|
||||||
}
|
}
|
||||||
@@ -567,7 +608,7 @@ $okButton.Add_Click({
|
|||||||
if ($groupType -eq 'Global') {
|
if ($groupType -eq 'Global') {
|
||||||
if (-not (Get-ADGroupMember -Identity $dlGroup -Recursive | Where-Object { $_.SamAccountName -eq $gg })) {
|
if (-not (Get-ADGroupMember -Identity $dlGroup -Recursive | Where-Object { $_.SamAccountName -eq $gg })) {
|
||||||
Add-ADGroupMember -Identity $dlGroup -Members $gg
|
Add-ADGroupMember -Identity $dlGroup -Members $gg
|
||||||
Add-DebugMessage "Globalgruppe $gg wurde zur Globalgruppe $dlGroup hinzugefügt." "Green"
|
Add-DebugMessage "Globalgruppe $gg wurde zur Globalgruppe $dlGroup hinzugefügt." "Green"
|
||||||
} else {
|
} else {
|
||||||
Add-DebugMessage "Globalgruppe $gg ist bereits Mitglied der Globalgruppe $dlGroup." "Orange"
|
Add-DebugMessage "Globalgruppe $gg ist bereits Mitglied der Globalgruppe $dlGroup." "Orange"
|
||||||
}
|
}
|
||||||
@@ -582,9 +623,9 @@ $okButton.Add_Click({
|
|||||||
if ($groupType -eq 'DomainLocal') {
|
if ($groupType -eq 'DomainLocal') {
|
||||||
if (-not (Get-ADGroupMember -Identity $dlGroup -Recursive | Where-Object { $_.SamAccountName -eq $gg })) {
|
if (-not (Get-ADGroupMember -Identity $dlGroup -Recursive | Where-Object { $_.SamAccountName -eq $gg })) {
|
||||||
Add-ADGroupMember -Identity $dlGroup -Members $gg
|
Add-ADGroupMember -Identity $dlGroup -Members $gg
|
||||||
Add-DebugMessage "Globalgruppe $gg wurde zur Domänenlokalen Gruppe $dlGroup hinzugefügt." "Green"
|
Add-DebugMessage "Globalgruppe $gg wurde zur Domänenlokalen Gruppe $dlGroup hinzugefügt." "Green"
|
||||||
} else {
|
} else {
|
||||||
Add-DebugMessage "Globalgruppe $gg ist bereits Mitglied der Domänenlokalen Gruppe $dlGroup." "Orange"
|
Add-DebugMessage "Globalgruppe $gg ist bereits Mitglied der Domänenlokalen Gruppe $dlGroup." "Orange"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -595,20 +636,20 @@ $okButton.Add_Click({
|
|||||||
Add-DebugMessage $separator "Black"
|
Add-DebugMessage $separator "Black"
|
||||||
|
|
||||||
[System.Windows.Forms.MessageBox]::Show("Vorgang abgeschlossen.")
|
[System.Windows.Forms.MessageBox]::Show("Vorgang abgeschlossen.")
|
||||||
})
|
})
|
||||||
$form.Controls.Add($okButton)
|
$form.Controls.Add($okButton)
|
||||||
|
|
||||||
# Beenden-Button
|
# Beenden-Button
|
||||||
$exitButton = New-Object System.Windows.Forms.Button
|
$exitButton = New-Object System.Windows.Forms.Button
|
||||||
$exitButton.Text = "Beenden"
|
$exitButton.Text = "Beenden"
|
||||||
$exitButton.Location = New-Object System.Drawing.Point(400, 355)
|
$exitButton.Location = New-Object System.Drawing.Point(400, 355)
|
||||||
$exitButton.Size = New-Object System.Drawing.Size(380, 30)
|
$exitButton.Size = New-Object System.Drawing.Size(380, 30)
|
||||||
$exitButton.Add_Click({
|
$exitButton.Add_Click({
|
||||||
$form.Close()
|
$form.Close()
|
||||||
})
|
})
|
||||||
$form.Controls.Add($exitButton)
|
$form.Controls.Add($exitButton)
|
||||||
|
|
||||||
$form.ShowDialog()
|
$form.ShowDialog()
|
||||||
}
|
}
|
||||||
|
|
||||||
# Erstellen des Formulars
|
# Erstellen des Formulars
|
||||||
@@ -620,21 +661,21 @@ $form.Size = New-Object Drawing.Size(300, 200)
|
|||||||
$btnCreateUser = New-Object Windows.Forms.Button
|
$btnCreateUser = New-Object Windows.Forms.Button
|
||||||
$btnCreateUser.Text = 'Create User'
|
$btnCreateUser.Text = 'Create User'
|
||||||
$btnCreateUser.Size = New-Object Drawing.Size(250, 40)
|
$btnCreateUser.Size = New-Object Drawing.Size(250, 40)
|
||||||
$btnCreateUser.Location = New-Object Drawing.Point(20, 30)
|
$btnCreateUser.Location = New-Object Drawing.Point(20, 10)
|
||||||
$btnCreateUser.Add_Click({ Create-User })
|
$btnCreateUser.Add_Click({ Create-User })
|
||||||
|
|
||||||
# Erstellen des Buttons für "Create Groups"
|
# Erstellen des Buttons für "Create Groups"
|
||||||
$btnCreateGroups = New-Object Windows.Forms.Button
|
$btnCreateGroups = New-Object Windows.Forms.Button
|
||||||
$btnCreateGroups.Text = 'Create Groups'
|
$btnCreateGroups.Text = 'Create Groups'
|
||||||
$btnCreateGroups.Size = New-Object Drawing.Size(250, 40)
|
$btnCreateGroups.Size = New-Object Drawing.Size(250, 40)
|
||||||
$btnCreateGroups.Location = New-Object Drawing.Point(20, 80)
|
$btnCreateGroups.Location = New-Object Drawing.Point(20, 60)
|
||||||
$btnCreateGroups.Add_Click({ Create-Groups })
|
$btnCreateGroups.Add_Click({ Create-Groups })
|
||||||
|
|
||||||
# Erstellen des Buttons für "ADGDL"
|
# Erstellen des Buttons für "AGDLP"
|
||||||
$btnADGDL = New-Object Windows.Forms.Button
|
$btnADGDL = New-Object Windows.Forms.Button
|
||||||
$btnADGDL.Text = 'ADGDL'
|
$btnADGDL.Text = 'AGDLP'
|
||||||
$btnADGDL.Size = New-Object Drawing.Size(250, 40)
|
$btnADGDL.Size = New-Object Drawing.Size(250, 40)
|
||||||
$btnADGDL.Location = New-Object Drawing.Point(20, 130)
|
$btnADGDL.Location = New-Object Drawing.Point(20, 110)
|
||||||
$btnADGDL.Add_Click({ ADGDL })
|
$btnADGDL.Add_Click({ ADGDL })
|
||||||
|
|
||||||
# Hinzufügen der Buttons zum Formular
|
# Hinzufügen der Buttons zum Formular
|
||||||
|
|||||||
Reference in New Issue
Block a user