How can i move Multiple Users from one OU to another using powershell

Viewed 38

Hi I'm completely new to this, I want to move multiple users from one place to another. I have following Code:

$objectlocation= 'OU=StdUsers,OU=UsersAndGroups,OU=Accounts,DC=ad,DC=shared'
$newlocation = 'OU=RegionBased,OU=Workstations,DC=ad,DC=shared'

$from = new-object System.DirectoryServices.DirectoryEntry("LDAP://$objectLocation")
$to = new-object System.DirectoryServices.DirectoryEntry("LDAP://$newlocation")
$from.MoveTo($newlocation,$from.name)

Inside RegionBased and StdUsers I have multiple country OU's inside which have have different sites in which users are present.

Its something like this

'OU=Test1,OU=India,OU=StdUsers,OU=UsersAndGroups,OU=Accounts,DC=ad,DC=shared'
'OU=Test2,OU=India,OU=StdUsers,OU=UsersAndGroups,OU=Accounts,DC=ad,DC=shared'
'OU=Test3,OU=USA,OU=StdUsers,OU=UsersAndGroups,OU=Accounts,DC=ad,DC=shared'

And inside Test1 and Test2 there are multiple users.

Same structures goes with Destination.

'OU=Test1,OU=India,OU=RegionBased,OU=UsersAndGroups,OU=Accounts,DC=ad,DC=shared'
'OU=Test2,OU=India,OU=RegionBased,OU=UsersAndGroups,OU=Accounts,DC=ad,DC=shared'
'OU=Test3,OU=USA,OU=RegionBased,OU=UsersAndGroups,OU=Accounts,DC=ad,DC=shared'

Any help will be thankfull.

0 Answers
Related