Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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:
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
You can’t perform that action at this time.