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 16
Alex Green3rd Line Server SupportAsked:
Who is Participating?
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
0
Alex Green3rd Line Server SupportAuthor 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
0
Alex Green3rd Line Server SupportAuthor Commented:
Oh sorry, no idea why that put that in there.

Thanks
Alex
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

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

0
Alex Green3rd Line Server SupportAuthor 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
0
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

0
Alex Green3rd Line Server SupportAuthor Commented:
I'll give that a shot shortly, thanks
0
Alex Green3rd Line Server SupportAuthor Commented:
No that doesn't work, any other ideas?
0
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

0

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 Green3rd Line Server SupportAuthor Commented:
This worked, sorry about the delay.

Thanks
Alex
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.