PS Script Required: move bulk users from one OU to other in same AD

PS Script Required:  move bulk users from one OU to other in same AD.
LVL 1
Murty MAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
Just all users found in the source OU?
In test mode, will only display which users it would move; remove the -WhatIf at the end to run it for real.
$sourceOU = (Get-ADOrganizationalUnit -Filter "name -eq 'Source'").DistinguishedName
$targetOU = (Get-ADOrganizationalUnit -Filter "name -eq 'Target'").DistinguishedName
Get-ADUser -Filter *  -SearchBase $sourceOU -ResultSetSize $null | Move-ADObject -TargetPath $targetOU -WhatIf

Open in new window

Murty MAuthor Commented:
I have a single domain and different OUs in that domain.
There are like 2500 users in 30 OUs.
1. I need out of 2500 users, 400 users move in to Newly created OU -- First Script.
2. New users ( not part of these 2500) to add in to domain and part of new ou. -- Second Script.
oBdACommented:
So how do you identify the users that need moving? Do you have a csv with SamAccountNames?
Murty MAuthor Commented:
Yes.  I have user names.
oBdACommented:
So assuming you have a csv with a header row and a column "SamAccountName", you can use the following.
As before in test mode, will only display which users it would move; remove the -WhatIf at the end of line 4 to run it for real.
$targetOU = (Get-ADOrganizationalUnit -Filter "name -eq 'Target'").DistinguishedName
Import-Csv -Path 'C:\Temp\MoveUsers.csv' | ForEach-Object {
	Write-Host "Processing $($_.SamAccountName) ..."
	Get-ADUser -Identity $_.SamAccountName | Move-ADObject -TargetPath $targetOU -WhatIf
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.