Creating list of Open and Closed set groups in AD

Posted: April 19, 2011 in Active Directory, Scripts

I used the following to identify open and closed set groups in our AD infrastructure. This was to aid in migration to a new child domain. I’ve used “Sites” as variables, as in the current environment, each “site” had its own OU. Not be confused with AD Sites. The script uses the Quest AD tools.

$Sites = @(“Site A”,”Site B”)
foreach ($Site in $Sites){
$OpenGroups = @(“”)
$ClosedGroups = @(“”)
$Groups = get-qadgroup -searchroot “domain.local/$Site”
foreach ($Group in $Groups){
$Type = “”
$Users = get-qadgroupmember -identity $Group
foreach ($i in $Users){
$Found = get-qaduser -SearchRoot “domain.local/$Site” -Name $i.Name
if ($Found -eq $null){
$Type = “Open”
}
}
if ($Type -eq “Open”){
$OpenGroups = $OpenGroups + $Group.name
}
else{
$ClosedGroups = $ClosedGroups + $Group.name
}
}
$OpenGroups|Sort-Object|Get-Unique|Out-File C:\Scripts\$Site-OpenGroup.txt -Append
$ClosedGroups|Sort-Object|Get-Unique| Out-File C:\Scripts\$Site-ClosedGroup.txt -Append
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s