SAM IT
asked on
Add users to security group from csv
Hi,
I tried the script, it adds the users which are in first line in the CSV, however when I have users more than one, it gives the following error:
adding users to group "narasimha.s"
- Cannot find an object with identity: '' under: 'DC=test,DC=local'.
CSV format:
Group Samaccount
DL-WGK-US-Houston-Projects -XXXXXX-RW Test102
GG-WGP-US-test-Projects-XX XXXX-RO-TE ST
Narasimha.S
I tried the script, it adds the users which are in first line in the CSV, however when I have users more than one, it gives the following error:
adding users to group "narasimha.s"
- Cannot find an object with identity: '' under: 'DC=test,DC=local'.
CSV format:
Group Samaccount
DL-WGK-US-Houston-Projects
GG-WGP-US-test-Projects-XX
Narasimha.S
Import-Module ActiveDirectory
Import-Csv "C:\Users\a.narasimha.s\Desktop\Project folder creation\Adduserstogroup.txt" |
ForEach `
{
$users = @($_.samAccount -split ",")
$group = $_.group
write-output "adding users to group ""$group"""
#$users
$users |
ForEach `
{
try
{
$user = $_
Add-ADGroupMember -Identity $group -Members $user
}
catch
{ Write-Output "$user - $($error[0].exception.message)" }
}
}
ASKER
I need to add multiple users and security groups to one security group
ASKER
Input should be from CSV. The mentioned script works fine but it consider only first line in the CSV . It wont consider the samaccount details from the second line
Why are you nesting groups like that and then putting in users, that makes no sense at all
So you don't want to repeat the group name in each line of the csv, but continue with the last one when the the next line contains a user name, but no group name?
Import-Module ActiveDirectory
Import-Csv "C:\Users\a.narasimha.s\Desktop\Project folder creation\Adduserstogroup.txt" | ForEach-Object {
If ($_.Group) {
$Group = $_.Group
}
$Users = @($_.samAccount -split ",")
Write-Output "Adding users to group '$($Group)'"
ForEach ($User In Users) {
Write-Output " - '$($User)'"
Try {
Add-ADGroupMember -Identity $Group -Members $User -ErrorAction Stop
} Catch {
Write-Output "'$($User) - $($Error[0].Exception.Message)"
}
}
}
ASKER
Got your point.
Add the users mentioned in the form to the Global Group and add the Global group to Domainlocal group.
Users requesting for Modify access should add to Global group and Global group should be added to Domain local group
Add the users mentioned in the form to the Global Group and add the Global group to Domainlocal group.
Users requesting for Modify access should add to Global group and Global group should be added to Domain local group
ASKER
@obda : Want to add multiple users to security group using csv Input
That is obvious; but what you posted as a sample is not a csv; based on your editing looks like you have a csv where the group name is not set in every row, indicating that the last available group name should be used for rows without group name.
In other words, a csv like this (spaces added for clarity):
If not, please attach the actual csv you're using, or post it inside [code][/code] blocks, without format changes (so no removal of delimiters, no adding of spaces etc.).
In other words, a csv like this (spaces added for clarity):
"Group", "Samaccount"
"Group1", "Member1Group1"
"", "Member2Group1"
"", "Member3Group1"
"Group2", "Member1Group2"
"", "Member2Group2"
If so, the script I posted above should be able to do this.If not, please attach the actual csv you're using, or post it inside [code][/code] blocks, without format changes (so no removal of delimiters, no adding of spaces etc.).
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello,
I have open question . can you assist
https://www.experts-exchange.com/questions/29015469/Need-to-Change-ACL-Permissions-and-disable-in-heritance-for-subfolders.html
I have open question . can you assist
https://www.experts-exchange.com/questions/29015469/Need-to-Change-ACL-Permissions-and-disable-in-heritance-for-subfolders.html
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.
I have recommended this question be closed as follows:
Accept: oBdA (https:#a42088526)
If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.
exchangepro
Experts-Exchange Cleanup Volunteer
I have recommended this question be closed as follows:
Accept: oBdA (https:#a42088526)
If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.
exchangepro
Experts-Exchange Cleanup Volunteer
Open in new window