scripts/ad_user_groups.ps1 hinzugefügt
This commit is contained in:
17
scripts/ad_user_groups.ps1
Normal file
17
scripts/ad_user_groups.ps1
Normal file
@@ -0,0 +1,17 @@
|
||||
# Import der CSV-Datei
|
||||
$csvPath = "path\to\your\csvfile.csv"
|
||||
$csvData = Import-Csv -Path $csvPath
|
||||
|
||||
# Durchlaufen jeder Zeile der CSV-Datei
|
||||
foreach ($row in $csvData) {
|
||||
# Erstellung des Benutzers
|
||||
New-ADUser -Name $row.Name -GivenName $row.FirstName -Surname $row.LastName -SamAccountName $row.SAMAccountName -UserPrincipalName $row.UPN -Path $row.OU -AccountPassword (ConvertTo-SecureString $row.Password -AsPlainText -Force) -Enabled $true
|
||||
|
||||
# Wenn die Gruppe existiert, füge den Benutzer hinzu, andernfalls erstelle die Gruppe und füge den Benutzer hinzu
|
||||
if (Get-ADGroup -Filter "Name -eq '$($row.Group)'") {
|
||||
Add-ADGroupMember -Identity $row.Group -Members $row.SAMAccountName
|
||||
} else {
|
||||
New-ADGroup -Name $row.Group -GroupScope Global -Path $row.GroupOU
|
||||
Add-ADGroupMember -Identity $row.Group -Members $row.SAMAccountName
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user