AD group consolidation

Good morning all and Happy New Year!

So, I've been tasked with doing an AD Consolidation, I'm struggling completely with the PowerShell.

Basically, all I need to do is search the subgroups of a top-level group.

So the top level group would be imported from a text file, we'll call it "Microsoft Office", beneath this we would have branches, such as

"ABC-Microsoft Office"
"DEF-Microsoft Office"

This would then have the computer accounts in it. I need to take the computer accounts from "ABC-Microsoft office" and put them into "Microsoft office".

However, there are multiple groups associated with the top level group, so I need it to go through all of them, using something like "Get-adgroupmember "Microsoft Office" move all the accounts and then I'll prep to delete the subgroups at a later stage.

Does anyone have a script they used before for this sort of work?

Thanks
Alex
LVL 19
Alex GreenProject Systems EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David SandCommented:
You can try Sysmalogic AD report builder to easily get all info you need without using any powershell.
It's a  30 days trial, but converts into a fully functional free version after, with some features inactive such as excel export, multiple bulk import etc.
can be downloaded from www.sysmalogic.com
Thanks
David
Alex GreenProject Systems EngineerAuthor Commented:
Yeah, but I know I can use PowerShell for this, I just need to get the reporting function sorted out correctly and that's where I'm struggling.

Also, I can just get the computers of all associated groups and then dump it into a separate scripts which is what I'll need to do I think
Alex GreenProject Systems EngineerAuthor Commented:
Oh sorry, no idea why that put that in there.

Thanks
Alex
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

RobertSystem AdminCommented:
for powershell you would need to use something like the Get-ADGroupMember using the Recursive option.

i.e.
Get-ADGroupMember -identity $group -recursive | select name | Export-csv -path $output -NoTypeInformation 

Open in new window

Alex GreenProject Systems EngineerAuthor Commented:
$groups = get-content 'C:\Powershell Projects\Group Consolidation\Groups.txt'
 foreach ($group in $groups)
         {Get-ADGroupMember -identity $group -recursive | select name -OutVariable $Computer | Add-ADGroupMember -Identity $group -Members $Computer}

Open in new window


It's not taking my outvariable which is somewhat annoying
RobertSystem AdminCommented:
I would split it like this:
$groups = get-content 'C:\Powershell Projects\Group Consolidation\Groups.txt'
 foreach ($group in $groups)
         {
  $computers = (Get-ADGroupMember -identity $group -recursive | select name)
         
  foreach ($computer in $computers)
        {
        Add-ADGroupMember -Identity $group -Members $Computer
        }
  }

Open in new window

Alex GreenProject Systems EngineerAuthor Commented:
I'll give that a shot shortly, thanks
Alex GreenProject Systems EngineerAuthor Commented:
No that doesn't work, any other ideas?
RobertSystem AdminCommented:
Sorry have been away for a while just getting back to this.

forgot you would need to add the $ to the computer name.
$groups = get-content 'C:\temp\Group.txt'
 foreach ($group in $groups)
         {
  $computers = (Get-ADGroupMember -identity $group -recursive | select name)

         
  foreach ($computer in $computers)
        {
    $computername = $computer.name + '$'
        Add-ADGroupMember -ID $group -Members $computername
        }
  }

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Alex GreenProject Systems EngineerAuthor Commented:
This worked, sorry about the delay.

Thanks
Alex
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.