header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Moving objects in AD
Last Post 01 Sep 2008 09:56 AM by VulakAerr. 2 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
VulakAerrUser is Offline
New Member
New Member
Posts:3

--
28 Aug 2008 11:01 AM  

Hi,

Could anyone tell me how to move an object from one OU to another in Active Directory using PowerShell? Can PowerShell do this out of the box?

Thanks.

 

John.

jdelatorreUser is Offline
New Member
New Member
Posts:18

--
28 Aug 2008 04:38 PM  
Yes you can. You can use the ADSI Type accelerator for this.

First attach to the object. I'm getting a computer object here.

$objComp = [adsi]"LDAP://cn=yourcomputername,ou=yourofficeou,dc=yourdomain,dc=com"

Once you have the computer object you now have access to its methods and properties. You can look at the method we are interested in by piping the object to get-member; the method we are interested in is call MoveTo. The catch here is that the ADSI methods are hidden under psbase. So you must go thru psbase to get access to the ADSI raw methods.

This line will give you insight on what parameters you'll need to pass to the 'Moveto' method.
$objcomp.PSBase | gm -MemberType method | ? { $_.name -eq 'moveto' }

Running the above code will display the following.

Name MemberType Definition
---- ---------- ----------
MoveTo Method System.Void MoveTo(DirectoryEntry newParent), System.Void MoveTo(DirectoryEntry newParent, String newName)

Now that you know how to call the method you can now call it.

$objComp.PSBase.MoveTo("LDAP://ou=destOU,dc=yourdomain,dc=com")
VulakAerrUser is Offline
New Member
New Member
Posts:3

--
01 Sep 2008 09:56 AM  
Thank you very much for this. It's a great help and exactly what I needed.
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer