Anthony K O365
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!
Thanks!
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
Expressions are only allowed as the first element of a pipeline.
At C:\find_move_users.ps1:3 char:2
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
perhaps (untested) remove the -whatif if it works.
$userstomove = import-csv "C:\Scripts\UsersToMove.cs v"
foreach ($user in $userstomove) {
Get-ADUser $user.UserName | Move-ADObject -TargetPath $user.NewOU
} - whatif
$userstomove = import-csv "C:\Scripts\UsersToMove.cs
foreach ($user in $userstomove) {
Get-ADUser $user.UserName | Move-ADObject -TargetPath $user.NewOU
} - whatif
ASKER
This was a great help!
Get-ADUser $_.UserName | Move-ADObject -TargetPath "$_.NewOU"
}
NewOU should be in the format of "OU=name,OU=name2,DC=domai