Creating an AD User from a Template in Powershell

Welcome Forums General PowerShell Q&A Creating an AD User from a Template in Powershell

Viewing 5 reply threads
  • Author
    Posts
    • #259891
      Participant
      Topics: 2
      Replies: 5
      Points: 36
      Rank: Member

      Hi,

      I have a VM where I’m practicing Powershell. I have been able to successfully create new active directory users and also templates.
      However when it comes to creating an AD User based of a template via powershell , I’m not able to accomplish that. Will someone please assist or point me in the right direction.

      For example, this is what I tried doing.

      I have created a Template called IT Template, and that IT template is part of different groups(Members of tab)
      When I create new users, I want it to use the properties of the IT Template so I don’t have to add all of the groups manually.

      I know I can add it Manually, like this.
      add-adgroupmember -Identity “Office” -members “test user”
      This will add the Office group to the user called test user.
      However I want to attach this to the template level.

      Can you provide me with a basic example so I can start understanding this.

      Thanks

      Regards,
      Jasiel

    • #260011
      Participant
      Topics: 25
      Replies: 197
      Points: 718
      Helping Hand
      Rank: Major Contributor

      retrieve the ad groups your template user is a member of

      $groupstoadd = get-adprincipalgroupmembership templateidhere

      then loop through the groups and add to your user

    • #260062
      Participant
      Topics: 2
      Replies: 5
      Points: 36
      Rank: Member

      retrieve the ad groups your template user is a member of

      $groupstoadd = get-adprincipalgroupmembership templateidhere

      then loop through the groups and add to your user

      Thanks, can you show me in a small example how to achieve this. I can’t wrap my head around it.

    • #260229
      Participant
      Topics: 25
      Replies: 197
      Points: 718
      Helping Hand
      Rank: Major Contributor
    • #260418
      Participant
      Topics: 2
      Replies: 5
      Points: 36
      Rank: Member

      I’m not sure where the code would be. Here is what I have.

    • #260961
      Participant
      Topics: 25
      Replies: 197
      Points: 718
      Helping Hand
      Rank: Major Contributor

      so the values you’re inputting there are distinct to the new user.

      if you want to use values from the template user for any other ad attributes you will need to retrieve it.

      $template = get-aduser templateidhere

      you will need to add any properties you want to copy to the new user utilizing the -properties argument.

      the $template line can be added after line 2.

      (this of course is assuming your “template” is an actual ad user object you’ve built)

      for the group membership, you need to perform that action after your new-aduser command builds your new user object

Viewing 5 reply threads
  • You must be logged in to reply to this topic.