Link to home
Start Free TrialLog in
Avatar of Anthony K O365
Anthony K O365Flag for United States of America

asked on

Script to Find, Move AD Users from csv

I am looking for script (powershell or vbs) that will find and move users in a csv file from one OU to another. Can you assist?

Thanks!
Avatar of Neil Russell
Neil Russell
Flag of United Kingdom of Great Britain and Northern Ireland image

import-csv "C:\Scripts\UsersToMove.csv" | {
Get-ADUser $_.UserName | Move-ADObject -TargetPath "$_.NewOU"
}


NewOU should be in the format of "OU=name,OU=name2,DC=domain,DC=COM"
Avatar of Anthony K O365

ASKER

I get the following error:

Expressions are only allowed as the first element of a pipeline.
At C:\find_move_users.ps1:3 char:2
ASKER CERTIFIED SOLUTION
Avatar of slidingfox
slidingfox
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
perhaps (untested) remove the -whatif if it works.
$userstomove = import-csv "C:\Scripts\UsersToMove.csv"
foreach ($user in $userstomove) {

Get-ADUser $user.UserName | Move-ADObject -TargetPath $user.NewOU
} - whatif
This was a great help!