Automating MemberOf category for AD

Welcome Forums General PowerShell Q&A Automating MemberOf category for AD

This topic contains 1 reply, has 2 voices, and was last updated by

4 years, 4 months ago.

  • Author
  • #20641

    Points: 0
    Rank: Member

    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

    Points: 1
    Rank: Member

    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:

    1. run New-ADUser
    2. loop thru the groups (depends on how you have the groups in the csv)
    3. add user to group (Add-ADGroupMember)


    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

The topic ‘Automating MemberOf category for AD’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort