Hello there,
I would suggest checking the CSV files and the data.
To specify the group and members we can use the following values:
-distinguished name
-objectGUID (GUID)
-objectSid (security identifier)
-SAMAccountName (Security Account Manager account name)
You can import CSV file in PowerShell scripts and load users in a local variable as below
#Import csv file and loads adusers in variable
$Users = Import-Csv -Path "C:\adusers.csv"
#Iterate AdUsers to add user account in Group
foreach($User in $Users){
try
{
Add-ADGroupMember -Identity Finance -Members $User.User -ErrorAction Stop -Verbose
}
catch
{
Write-Host "Error while adding user to adgroup"
}
}
Hope this resolves your Query !!
--If the reply is helpful, please Upvote and Accept it as an answer–
Get and add users to securoty group
Trying add users with a specific details in the company field in AD to a security group and was not able to. Below is the script, any help?
#Retrieve a list of users with '123' in AD company field.
Get-aduser -Server (server name) -properties Company -Filter { enabled -eq $true -and company -like "Testing" } | select name, | Export-Csv C:\Temp\123.csv
$Users = Import-Csv "C:\Temp\123.csv"
foreach ($User in $Users) {
Add-ADGroupMember -Identity "123-Users" -Members $users }
Windows for business Windows Client for IT Pros Directory services Active Directory
Windows for business Windows Server User experience PowerShell
2 answers
Sort by: Most helpful
-
Limitless Technology 44,751 Reputation points
2023-02-13T17:20:09.84+00:00 -
Deleted
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more