scripts/ad_users_sa_window.ps1 aktualisiert
This commit is contained in:
@@ -26,19 +26,28 @@ $dataGridView.Columns[6].Name = "OU"
|
|||||||
$dataGridView.Columns[7].Name = "DC"
|
$dataGridView.Columns[7].Name = "DC"
|
||||||
|
|
||||||
# Beispielzeilen hinzufügen
|
# Beispielzeilen hinzufügen
|
||||||
$dataGridView.Rows.Add("Master", "", "", "", "", "", "", "")
|
$dataGridView.Rows.Add("Master", "", "", "", "", "", "DefaultOU", "DC=yourdomain,DC=com")
|
||||||
$dataGridView.Rows.Add("User", "", "", "", "", "", "", "")
|
$dataGridView.Rows.Add("User", "", "", "", "", "", "", "")
|
||||||
$dataGridView.Rows.Add("SA", "", "", "", "", "", "", "")
|
$dataGridView.Rows.Add("SA", "", "", "", "", "", "", "")
|
||||||
|
|
||||||
# DataGridView anpassen
|
# DataGridView anpassen
|
||||||
$dataGridView.AlternatingRowsDefaultCellStyle.BackColor = [System.Drawing.Color]::LightGray
|
$dataGridView.AlternatingRowsDefaultCellStyle.BackColor = [System.Drawing.Color]::LightGray
|
||||||
|
|
||||||
# Eventhandler hinzufügen, um Name und SAMAccountName in Echtzeit zu generieren
|
# Eventhandler hinzufügen, um Name, SAMAccountName und UPN in Echtzeit zu generieren und OU/DC zu übernehmen
|
||||||
$dataGridView.add_CellEndEdit({
|
$dataGridView.add_CellEndEdit({
|
||||||
param ($sender, $e)
|
param ($sender, $e)
|
||||||
$row = $dataGridView.Rows[$e.RowIndex]
|
$row = $dataGridView.Rows[$e.RowIndex]
|
||||||
|
|
||||||
# Name generieren
|
# Felder schreibgeschützt machen, wenn Typ SA ist
|
||||||
|
if ($row.Cells["Type"].Value -eq 'SA') {
|
||||||
|
$row.Cells["FirstName"].ReadOnly = $true
|
||||||
|
$row.Cells["LastName"].ReadOnly = $true
|
||||||
|
} else {
|
||||||
|
$row.Cells["FirstName"].ReadOnly = $false
|
||||||
|
$row.Cells["LastName"].ReadOnly = $false
|
||||||
|
}
|
||||||
|
|
||||||
|
# Name und SAMAccountName generieren
|
||||||
if ($row.Cells["FirstName"].Value -ne $null -and $row.Cells["LastName"].Value -ne $null -and $row.Cells["FirstName"].Value -ne "" -and $row.Cells["LastName"].Value -ne "") {
|
if ($row.Cells["FirstName"].Value -ne $null -and $row.Cells["LastName"].Value -ne $null -and $row.Cells["FirstName"].Value -ne "" -and $row.Cells["LastName"].Value -ne "") {
|
||||||
$row.Cells["Name"].Value = $row.Cells["FirstName"].Value + " " + $row.Cells["LastName"].Value
|
$row.Cells["Name"].Value = $row.Cells["FirstName"].Value + " " + $row.Cells["LastName"].Value
|
||||||
$samAccountName = $row.Cells["FirstName"].Value.Substring(0, 1).ToLower() + $row.Cells["LastName"].Value.ToLower()
|
$samAccountName = $row.Cells["FirstName"].Value.Substring(0, 1).ToLower() + $row.Cells["LastName"].Value.ToLower()
|
||||||
@@ -50,30 +59,17 @@ $dataGridView.add_CellEndEdit({
|
|||||||
$row.Cells["UPN"].Value = "$samAccountName@$upnDomain"
|
$row.Cells["UPN"].Value = "$samAccountName@$upnDomain"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Alle Felder außer Type ein- oder ausblenden
|
# OU und DC von der darüber liegenden Master-Zeile übernehmen
|
||||||
if ($row.Cells["Type"].Value -ne 'User' -and $row.Cells["Type"].Value -ne 'SA' -and $row.Cells["Type"].Value -ne 'Master') {
|
$aboveMasterRow = $null
|
||||||
for ($i = 1; $i -lt $row.Cells.Count; $i++) {
|
for ($i = ($e.RowIndex - 1); $i -ge 0; $i--) {
|
||||||
$row.Cells[$i].Style.BackColor = $form.BackColor
|
if ($dataGridView.Rows[$i].Cells["Type"].Value -eq 'Master') {
|
||||||
$row.Cells[$i].Style.ForeColor = $form.BackColor
|
$aboveMasterRow = $dataGridView.Rows[$i]
|
||||||
}
|
break
|
||||||
} else {
|
|
||||||
for ($i = 1; $i -lt $row.Cells.Count; $i++) {
|
|
||||||
$row.Cells[$i].Style.BackColor = [System.Drawing.Color]::White
|
|
||||||
$row.Cells[$i].Style.ForeColor = [System.Drawing.Color]::Black
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($aboveMasterRow -ne $null) {
|
||||||
# FirstName und LastName-Feld durchsichtig machen oder ausblenden, wenn Typ SA oder Master ist
|
$row.Cells["OU"].Value = $aboveMasterRow.Cells["OU"].Value
|
||||||
if ($row.Cells["Type"].Value -eq 'SA' -or $row.Cells["Type"].Value -eq 'Master') {
|
$row.Cells["DC"].Value = $aboveMasterRow.Cells["DC"].Value
|
||||||
$row.Cells["FirstName"].Style.BackColor = $form.BackColor
|
|
||||||
$row.Cells["FirstName"].Style.ForeColor = $form.BackColor
|
|
||||||
$row.Cells["LastName"].Style.BackColor = $form.BackColor
|
|
||||||
$row.Cells["LastName"].Style.ForeColor = $form.BackColor
|
|
||||||
} else {
|
|
||||||
$row.Cells["FirstName"].Style.BackColor = [System.Drawing.Color]::White
|
|
||||||
$row.Cells["FirstName"].Style.ForeColor = [System.Drawing.Color]::Black
|
|
||||||
$row.Cells["LastName"].Style.BackColor = [System.Drawing.Color]::White
|
|
||||||
$row.Cells["LastName"].Style.ForeColor = [System.Drawing.Color]::Black
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user