Add users to groups as part of New-ADUser process?

Welcome Forums General PowerShell Q&A Add users to groups as part of New-ADUser process?

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

 
Participant
5 years, 2 months ago.

  • Author
    Posts
  • #7544

    Participant
    Points: 1
    Rank: Member

    Hi All,

    I'm using Import-Csv and New-ADUser to create a whole bunch of new users. This is working fine.

    However, we have 27 different Active Directory groups for the various company job roles. Each user only needs to belong to a single AD group to get everything they need.

    Is there a way of specifying group membership as part of the user creation process? I noticed there's no '-memberof' parameter in New-ADUser or Set-ADUser.

    I'm already using 'Foreach-Object'. Can I use it again in the same line?

    I've also tried to put the whole command in parentheses like this:

    Add-ADGroupmember 'AD Role Group' (Import-Csv Users.csv | For-Each {New-ADUser etc.etc})

    (Kinda suspected that wouldn't work before I tried).

    Any suggestions?

    Cheers.

  • #11053

    Participant
    Points: 1
    Rank: Member

    Hi Don,

    Many thanks for this. Due to my limited experience/knowledge of Powershell at the time, I still struggled with this task. I haven't had to create any AD accounts for a while, but I've been using Powershell for various tasks every day since.

    We've just had a bunch of new user requests come in, so I revisited this script. I've got it working now. (Would never have known to use the -Passthru switch).

    Cheers.

    TG

The topic ‘Add users to groups as part of New-ADUser process?’ is closed to new replies.