Untitled
unknown
powershell
2 years ago
1.1 kB
4
Indexable
# Define the path to the CSV file $csvPath = "C:\users\fle\acc_test.csv" # Import the CSV file $csvPath = Read-Host ".csv-Pfad angeben" $emailAddresses = Import-Csv -Path $csvPath # Define the group name $groupName = Read-Host "AD-Gruppe angeben" $groupName = # Create an array to store the users $users = @() # Loop through each email address foreach ($entry in $emailAddresses) { $email = $entry.Email # Get lthe username from the email address $username = $email.Split("@")[0] # Retrieve the user from Active Directory $user = Get-ADUser -LDAPFilter "(mail=$email)" -Properties initials # Check if the user was found if ($user) { $users += $user Write-Host "User with email address '$email' found in Active Directory." } else { Write-Host "User with email address '$email' not found in Active Directory." } } # Loop through users adding them to an AD Group foreach ($user in $users) { Add-ADGroupMember -Identity $groupName -Members $user }
Editor is loading...