kuzum
asked on
add list of users into Global Security Group
Hi
I have a Global Security group that I need to import over 100 users and I tried this. Where am I going wrong with this?
import-module activedirectory
$list =import-csv "C:\test\export\userlist.c sv"
forEach ($user in $list)
{
add-ADGroupMember -identity mytestgroup -member $list
}
I have a Global Security group that I need to import over 100 users and I tried this. Where am I going wrong with this?
import-module activedirectory
$list =import-csv "C:\test\export\userlist.c
forEach ($user in $list)
{
add-ADGroupMember -identity mytestgroup -member $list
}
Maybe stating the way-too-obvious here, but you're using "$List" as member to add, not "$User".
On closer inspection, you're using the import incorrectly as well.
Either your csv is a real csv with a header row, in which case you need to use the property (column) of the rows you imported, for example "-member $User.DistinguishedName", or you're using a flat file without header, in which case you need to use "Get-Content" instead of "Import-Csv".
Either your csv is a real csv with a header row, in which case you need to use the property (column) of the rows you imported, for example "-member $User.DistinguishedName", or you're using a flat file without header, in which case you need to use "Get-Content" instead of "Import-Csv".
ASKER
hmm, thanks. I changed it to get-content and error changed. I also attached the csv file? did it need to be .txt?
Add-ADGroupMember : Cannot find an object with identity: 'SamAccountName' under: 'DC=xx,DC=xx,DC=local'.
At line:9 char:18
+ add-ADGroupMember <<<< -identity mytestGroup -member $user
+ CategoryInfo : ObjectNotFound: (SamAccountName:ADPrincipa l) [Add-ADGroupMember], ADIdentityNotFoundExceptio n
+ FullyQualifiedErrorId : SetADGroupMember.ValidateM embersPara meter,Micr osoft.Acti veDirector y.Manageme nt.Command s.AddADGro upMember
doc10.docx
Add-ADGroupMember : Cannot find an object with identity: 'SamAccountName' under: 'DC=xx,DC=xx,DC=local'.
At line:9 char:18
+ add-ADGroupMember <<<< -identity mytestGroup -member $user
+ CategoryInfo : ObjectNotFound: (SamAccountName:ADPrincipa
+ FullyQualifiedErrorId : SetADGroupMember.ValidateM
doc10.docx
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
@kazum-
Yes, generally you'd want to either paste the contents of the CSV into a code block or attach a .txt or .csv file (office documents can execute macros when downloaded so most experts won't open them.) You can also use a screenshot (png, jpg, etc)
To echo oBdA:
when you use this line:
For example, if your CSV is:
This code would do the following:
Yes, generally you'd want to either paste the contents of the CSV into a code block or attach a .txt or .csv file (office documents can execute macros when downloaded so most experts won't open them.) You can also use a screenshot (png, jpg, etc)
To echo oBdA:
when you use this line:
forEach ($user in $list)
You're creating each $user as a row in the CSV. So you use . and then the column name to reference the field.For example, if your CSV is:
First,Last,FavoriteColor
John,Test,Blue
This code would do the following:
$list = import-csv "C:\test\export\userlist.csv"
foreach ($user in $list) {
$output = $user.First + " " + $user.Last + "'s favorite color is " + $user.FavoriteColor + "."
Write-Host $output
}
Would write "John Test's favorite color is Blue."
ASKER
thank you for your excellent support gents