We help IT Professionals succeed at work.

Change OU's and groups within AD using powershell and variables.

Alex
Alex asked
on
239 Views
1 Endorsement
Last Modified: 2018-09-25
Good morning all,

So I have a new issue, Shocker with it being a Monday Morning and all. I've been told that I need to change site codes for a number of OU's and change the associated groups which reside either in that OU or somewhere else.

Now

I need to change only the site part of the group, i'm kind of debating deleting and recreating the groups however in the (Likely) event that I'll need to do this again I'm trying to make it self contained.

$OUs = Read-Host "Please enter the OU and Associated groups you'd like to change"

$NewOU = Read-Host "Please enter the new name of the OU and groups"

Foreach ($OU in $OUs){
Get-ADOrganizationalUnit -filter "Name -like $ou" | Set-ADOrganizationalUnit -DisplayName $NewOU }

Get-ADGroup -filter "Name -like $ou"

Open in new window



This is where I've got to and it's pretty shocking, maybe because I broke myself on Friday night and I've still got a headache.

Any hints on how I can do this would be great. I'm still trying to learn the intricacies of PowerShell so please advise rather than giving the straight answer :D

I don't think this is a hash group thing either.

Thanks
ALex
Comment
Watch Question

Managing Consultant
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Michael B. SmithManaging Consultant
CERTIFIED EXPERT

Commented:
I answered the question. I should get credit for it. Not a big deal, but still...
AlexA lack of information provides a lack of a decent solution.
CERTIFIED EXPERT

Author

Commented:
Yeah ok.... :-p