Created
September 28, 2018 09:27
-
-
Save gioxx/1843f68762a17aeb0bfb4cb50768e1e6 to your computer and use it in GitHub Desktop.
Lo script popola un gruppo di Active Directory inserendo al suo interno tutti gli utenti che trova all'interno di una OU specificata. Maggiori dettagli disponibili nell'articolo sul blog: https://wp.me/pdQ5q-9On
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module ActiveDirectory | |
$groupname = "CN=CONTOSO_Dipendenti,OU=Contoso,OU=Gruppi,DC=contoso,DC=local" | |
$users = Get-ADUser -Filter * -SearchBase "OU=Contoso,OU=Utenti,DC=contoso,DC=local" | |
foreach($user in $users) | |
{ | |
Add-ADGroupMember -Identity $groupname -Member $user.samaccountname -ErrorAction SilentlyContinue | |
} | |
$members = Get-ADGroupMember -Identity $groupname | |
foreach($member in $members) | |
{ | |
if($member.distinguishedname -notlike "*OU=Contoso,OU=Utenti,DC=contoso,DC=local*") | |
{ | |
Remove-ADGroupMember -Identity $groupname -Member $member.samaccountname | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment