scripts/AD_USER_CREATE.ps1 aktualisiert
This commit is contained in:
@@ -74,13 +74,15 @@ $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
|
$dataGridView.Columns[4].Name = "OU" # OU (wird als ComboBox hinzugefügt)
|
||||||
$dataGridView.Columns[5].Name = "Standardpasswort" # Standardpasswort
|
$dataGridView.Columns[5].Name = "Standardpasswort" # Standardpasswort
|
||||||
|
|
||||||
# Funktion zum Abrufen der verfügbaren OUs
|
# Dropdown für die OU in der DataGridView-ComboBox-Spalte
|
||||||
function Get-OUs {
|
$ouComboBoxColumn = New-Object System.Windows.Forms.DataGridViewComboBoxColumn
|
||||||
return Get-ADOrganizationalUnit -Filter * | Select-Object -ExpandProperty DistinguishedName
|
$ouComboBoxColumn.HeaderText = "OU"
|
||||||
}
|
$ouComboBoxColumn.Items.AddRange($ouList) # Hier fügen wir alle OUs hinzu
|
||||||
|
$dataGridView.Columns.RemoveAt(4) # Entfernt die ursprüngliche OU-Spalte
|
||||||
|
$dataGridView.Columns.Insert(4, $ouComboBoxColumn) # Fügt die ComboBox-Spalte an der richtigen Stelle ein
|
||||||
|
|
||||||
# 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 {
|
||||||
@@ -118,7 +120,7 @@ $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 # Nun enthält $ou den DistinguishedName der OU
|
$ou = $row.Cells[4].Value # Hier wird die ausgewählte OU aus der ComboBox abgerufen
|
||||||
$password = $row.Cells[5].Value
|
$password = $row.Cells[5].Value
|
||||||
|
|
||||||
# Überprüfen, ob notwendige Felder ausgefüllt sind
|
# Überprüfen, ob notwendige Felder ausgefüllt sind
|
||||||
@@ -151,7 +153,7 @@ $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 `
|
||||||
|
|||||||
Reference in New Issue
Block a user