Automatic group assign to user within OU

M.W.H 20 Reputation points
2023-07-06T07:06:54.5666667+00:00

Hello everyone,

I have a question. I have an OU with a few users in it. Is there a possiblity that whenever I add a user to the OU that they automatically get a specific group assigned? Perhaps a script?

This would be nice to have since every user within this OU needs the group. If this can be done automatically that would be nice.
I'd love to hear all the possibilities!

This is on Windows Server!

Windows for business | Windows Server | User experience | Other
0 comments No comments
{count} votes

Accepted answer
  1. Rafael da Rocha 5,251 Reputation points
    2023-07-06T09:55:50.7833333+00:00

    Hello,

    Quick way, you can have a script like this run on a schedule

    $Users = Get-ADUser -Filter * -SearchBase 'OU=TestOU,DC=Domain,DC=local' -SearchScope OneLevel -Properties MemberOf
    $Group = 'CN=TestGroup,DC=Domain,DC=local'
    foreach ($User in $Users) {
        if ($User.MemberOf -notcontains $Group) {
            Add-ADGroupMember $Group -Members $User.SamAccountName
        }
    }
    

    If this or any other reply helped solve your question, please remember to upvote and/or "Accept Answer".
    It helps others facing similar issues find the solution.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.