Combine two active directory group collections?

So I have the following code. Each line creates a collection of the groups pulled from active directory, from two different OUs. I need to combine them into a single collection that I can work on. Any help would be greatly appreciated.

$Groups2 = Get-ADGroup -Filter * -SearchBase “OU=RestrictedGroups,OU=Mycorp,DC=MYDOMAIN,DC=COM” -Server 192.168.1.1 -SearchScope Subtree -Credential $MDCred -Properties whenCreated, DisplayName,SAMAccountName

$Groups1 = Get-ADGroup -Filter * -SearchBase “OU=Groups,OU=Mycorp,DC=MYDOMAIN,DC=COM” -Server 192.168.1.1 -SearchScope Subtree -Credential $MDCred -Properties whenCreated, DisplayName,SAMAccountName

EDIT: This appears to work OK:

$Groups = Get-ADGroup -Filter * -SearchBase “OU=RestrictedGroups,OU=Mycorp,DC=MYDOMAIN,DC=COM” -Server 192.168.1.1 -SearchScope Subtree -Credential $MDCred -Properties whenCreated, DisplayName,SAMAccountName

$Groups ** += ** Get-ADGroup -Filter * -SearchBase “OU=Groups,OU=Mycorp,DC=MYDOMAIN,DC=COM” -Server 192.168.1.1 -SearchScope Subtree -Credential $MDCred -Properties whenCreated, DisplayName,SAMAccountName

submitted by /u/ilovetpb
[link] [comments]

Leave a Reply