views:

2123

answers:

2

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)
+1  A: 

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)
Steven Murawski
+4  A: 

Hi Steven. 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)
Eldila
Great!! Thanks for posting the update!
Steven Murawski