# Automating MemberOf category for AD

This topic contains 1 reply, has 2 voices, and was last updated by  Craig Duff 3 years, 6 months ago.

• Author
Posts
• #20641

Eric Bronnert
Participant

As the title says, I'm trying to figure out how to automate the MemberOf section on AD via Powershell by importing a CSV file and piping it into New-ADUser. I have looked through ADSI Edit and ADUsers syntax and can not find anything to use as a header for my information. What am I missing? I have tried using headers on my csv like MemberOf and Identity but to no avail.

• #20645

Craig Duff
Participant

If you are trying to import a csv file and pass it directly to new-aduser, then you are doing something called passing by property name. I.e. if you are doing this:

Import-CSV c:\in.csv | New-ADUser

To find out what the header/property names you can use do this:

Get-Help New-ADUser -Full

And look for properties that say: Accept pipeline input? True (ByPropertyName)

There is no property for New-ADUser that lets you define it's memberships, bypropertyname or otherwise.

You would have to loop thru the lines in the csv, and for each iteration of the loop:
[ol]
ForEach($line in$csv){
$line | select-object Name,SamAccountName,SurName,GivenName | New-ADUser ForEach($group in ($line.groups.split(";"))){ Add-ADGroupMember -Identity$group -Members \$line.SamAccountName