scripts/AD_AIO.ps1 aktualisiert
This commit is contained in:
@@ -82,15 +82,17 @@ $dataGridView.Columns[0].Name = "Titel" # Titel in der ersten Spalte
|
|||||||
$dataGridView.Columns[1].Name = "Vorname" # Vorname
|
$dataGridView.Columns[1].Name = "Vorname" # Vorname
|
||||||
$dataGridView.Columns[2].Name = "Nachname" # Nachname
|
$dataGridView.Columns[2].Name = "Nachname" # Nachname
|
||||||
$dataGridView.Columns[3].Name = "Globalgruppe" # Globalgruppe
|
$dataGridView.Columns[3].Name = "Globalgruppe" # Globalgruppe
|
||||||
$dataGridView.Columns[4].Name = "OU" # OU (wird als ComboBox hinzugefügt)
|
$dataGridView.Columns[4].Name = "Standardpasswort" # Standardpasswort
|
||||||
$dataGridView.Columns[5].Name = "Standardpasswort" # Standardpasswort
|
$dataGridView.Columns[5].Name = "OU" # OU (wird als ComboBox hinzugefügt)
|
||||||
|
$dataGridView.Columns[5].Width = 220
|
||||||
|
|
||||||
# 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
|
||||||
$ouComboBoxColumn.HeaderText = "OU"
|
$ouComboBoxColumn.HeaderText = "OU"
|
||||||
$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(4) # Entfernt die ursprüngliche OU-Spalte
|
$dataGridView.Columns.RemoveAt(5) # Entfernt die ursprüngliche OU-Spalte
|
||||||
$dataGridView.Columns.Insert(4, $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
|
||||||
|
|
||||||
# Funktion zum Setzen der OUs für alle Zeilen im DataGridView
|
# Funktion zum Setzen der OUs für alle Zeilen im DataGridView
|
||||||
function Update-OUsInGrid {
|
function Update-OUsInGrid {
|
||||||
@@ -98,7 +100,7 @@ function Update-OUsInGrid {
|
|||||||
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
|
||||||
# Setze die Master-OU in der "OU"-Spalte für jede Zeile
|
# Setze die Master-OU in der "OU"-Spalte für jede Zeile
|
||||||
$row.Cells[4].Value = $selectedMasterOU
|
$row.Cells[5].Value = $selectedMasterOU # Zeile aktualisieren, statt der 4. Spalte jetzt die 5. für OU
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,7 +121,7 @@ $form.Controls.Add($outputTextBox)
|
|||||||
# OK-Button erstellen
|
# OK-Button erstellen
|
||||||
$okButton = New-Object System.Windows.Forms.Button
|
$okButton = New-Object System.Windows.Forms.Button
|
||||||
$okButton.Text = "Benutzer erstellen"
|
$okButton.Text = "Benutzer erstellen"
|
||||||
$okButton.Size = New-Object System.Drawing.Size(150, 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
|
||||||
$okButton.Add_Click({
|
$okButton.Add_Click({
|
||||||
foreach ($row in $dataGridView.Rows) {
|
foreach ($row in $dataGridView.Rows) {
|
||||||
@@ -128,8 +130,8 @@ $okButton.Add_Click({
|
|||||||
$firstName = $row.Cells[1].Value
|
$firstName = $row.Cells[1].Value
|
||||||
$lastName = $row.Cells[2].Value
|
$lastName = $row.Cells[2].Value
|
||||||
$globalGroup = $row.Cells[3].Value
|
$globalGroup = $row.Cells[3].Value
|
||||||
$ou = $row.Cells[4].Value # Hier wird die ausgewählte OU aus der ComboBox abgerufen
|
$password = $row.Cells[4].Value
|
||||||
$password = $row.Cells[5].Value
|
$ou = $row.Cells[5].Value # Hier wird die ausgewählte OU aus der ComboBox abgerufen
|
||||||
|
|
||||||
# Ü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) {
|
||||||
@@ -161,14 +163,14 @@ $okButton.Add_Click({
|
|||||||
$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" `
|
New-ADUser -Name "$firstName $lastName"
|
||||||
-GivenName $firstName `
|
-GivenName $firstName
|
||||||
-Surname $lastName `
|
-Surname $lastName
|
||||||
-SamAccountName $username `
|
-SamAccountName $username
|
||||||
-UserPrincipalName $email `
|
-UserPrincipalName $email
|
||||||
-EmailAddress $email `
|
-EmailAddress $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
|
# Erfolgsnachricht für Benutzererstellung in grün
|
||||||
@@ -183,16 +185,16 @@ $okButton.Add_Click({
|
|||||||
|
|
||||||
# Gruppenzuordnung durchführen, auch wenn der Benutzer schon existiert
|
# Gruppenzuordnung durchführen, auch wenn der Benutzer schon existiert
|
||||||
if ($globalGroup) {
|
if ($globalGroup) {
|
||||||
# Gruppen-OU auswählen (aus der ComboBox für Gruppen)
|
# Gruppen-OU immer auf die Master-OU setzen
|
||||||
$groupOU = $masterGroupOUComboBox.SelectedItem
|
$groupOU = $masterGroupOU
|
||||||
try {
|
try {
|
||||||
# Überprüfen, ob die Gruppe existiert, und gegebenenfalls erstellen
|
# Überprüfen, ob die Gruppe existiert, und gegebenenfalls erstellen
|
||||||
$group = Get-ADGroup -Filter { Name -eq $globalGroup }
|
$group = Get-ADGroup -Filter { Name -eq $globalGroup }
|
||||||
if (-not $group) {
|
if (-not $group) {
|
||||||
# Gruppe erstellen, falls sie nicht existiert
|
# Gruppe erstellen, falls sie nicht existiert
|
||||||
New-ADGroup -Name $globalGroup `
|
New-ADGroup -Name $globalGroup
|
||||||
-GroupScope Global `
|
-GroupScope Global
|
||||||
-Path $groupOU `
|
-Path $groupOU
|
||||||
-Description "Globale Gruppe für $globalGroup"
|
-Description "Globale Gruppe für $globalGroup"
|
||||||
|
|
||||||
# Erfolgsnachricht für Gruppenerstellung
|
# Erfolgsnachricht für Gruppenerstellung
|
||||||
@@ -212,7 +214,7 @@ $okButton.Add_Click({
|
|||||||
} 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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,8 +223,8 @@ $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(150, 30) # Größe des Buttons festgelegt
|
$exitButton.Size = New-Object System.Drawing.Size(380, 30) # Größe des Buttons festgelegt
|
||||||
$exitButton.Location = New-Object System.Drawing.Point(624, 510) # Position des Beenden-Buttons
|
$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
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user