Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move Active Directory Group to Another OU using Powershell

How do I move an active directory group to another organizational unit using Powershell?

ie.

I would like to move the group "IT Department" from:

  (CN=IT Department, OU=Technology Department, OU=Departments,DC=Company,DC=ca)

to:

  (CN=IT Department, OU=Temporarily Moved Groups, DC=Company,DC=ca)
like image 625
Eldila Avatar asked Sep 16 '08 20:09

Eldila


2 Answers

Your script was really close to correct (and I really appreciate your response).

The following script is what I used to solve my problem.:

$from = [ADSI]"LDAP://CN=IT Department, OU=Technology Department, OU=Departments,DC=Company,DC=ca"
$to = [ADSI]"LDAP://OU=Temporarily Moved Groups, DC=Company,DC=ca"
$from.PSBase.MoveTo($to,"cn="+$from.name)
like image 197
Eldila Avatar answered Nov 15 '22 10:11

Eldila


I haven't tried this yet, but this should do it..

$objectlocation= 'CN=IT Department, OU=Technology Department, OU=Departments,DC=Company,DC=ca'
$newlocation = 'OU=Temporarily Moved Groups, DC=Company,DC=ca'

$from = new-object System.DirectoryServices.DirectoryEntry("LDAP://$objectLocation")
$to = new-object System.DirectoryServices.DirectoryEntry("LDAP://$newlocation")
$from.MoveTo($newlocation,$from.name)
like image 24
Steven Murawski Avatar answered Nov 15 '22 09:11

Steven Murawski