Skip to main content

Add all users in OU to security group

While working on figuring out how to add all of RS domestic to a security group quickly, developed this powershell script. 

It will quickly add all the users in the listed OU to the specific security group listed. 

 

 

 

Import-Module ActiveDirectory 

$ou = "OU=RHSC,DC=RHSC,DC=local" 

$grp = "SafetySite-Read" 

Get-ADUser -SearchBase $ou -Filter * | ForEach-Object {Add-ADGroupMember -Identity $grp -Members $_ } 

 

 

 

 

 

 

 

#see who is not a member of a security group within an OU 

 

$ou = "OU=RHSC,DC=RHSC,DC=local" 

$grp = "RSHub-Read" 

$results = @() 

$users = Get-ADUser  -SearchBase $ou  -Properties memberof -Filter *  

foreach ($user in $users) { 

    $groups = $user.memberof -join ';' 

    $results += New-Object psObject -Property @{'User'=$user.name;'Groups'= $groups} 

    } 

$results | Where-Object { $_.groups -notmatch $grp } | Select-Object user