Answered by:
How to move AD user accounts to a specified OU from CSV file

-
Hi all
I currently have a CSV file with one column of listed saMAccount names, though I need to search these accounts in Active directory and move them to a specified OU called "Terminal Services Accounts"
They all have one thing in common; their username / saMAccount names are firstname.lastname (logon name)If there is a script to utilise the CSV file, search these AD accounts and move them to the OU called "Terminal Services Accounts".
They can either be enabled or disabled accounts.
Thanks
Jon
Question
Answers
-
Thanks Mike,
I have found the following AD module for Powershell: to read my CSV file as samaccountnames then "move" them to the specified OU.
# Specify target OU. $TargetOU = "ou=NewUsers,ou=West,dc=MyDomain,dc=com,dc=au" # Read user sAMAccountNames from csv file (field labeled "Name"). Import-Csv -Path Users.csv | ForEach-Object { # Retrieve DN of User. $UserDN = (Get-ADUser -Identity $_.Name).distinguishedName # Move user to target OU. Move-ADObject -Identity $UserDN -TargetPath $TargetOU }
Thanks for your assistance- Marked as answer by Jonathan Georgiou Wednesday, March 11, 2015 4:25 AM
All replies
-
Hi Jon,
Prewritten scripts can be found in the repository here:
https://gallery.technet.microsoft.com/scriptcenter
If you'd like to take a crack at writing this yourself, you can use Move-ADObject to accomplish your goal:
http://ss64.com/ps/move-adobject.html
Let us know if you have any specific questions.
Don't retire TechNet! - (Don't give up yet - 13,225+ strong and growing)
-
Thanks Mike,
I have found the following AD module for Powershell: to read my CSV file as samaccountnames then "move" them to the specified OU.
# Specify target OU. $TargetOU = "ou=NewUsers,ou=West,dc=MyDomain,dc=com,dc=au" # Read user sAMAccountNames from csv file (field labeled "Name"). Import-Csv -Path Users.csv | ForEach-Object { # Retrieve DN of User. $UserDN = (Get-ADUser -Identity $_.Name).distinguishedName # Move user to target OU. Move-ADObject -Identity $UserDN -TargetPath $TargetOU }
Thanks for your assistance- Marked as answer by Jonathan Georgiou Wednesday, March 11, 2015 4:25 AM
-
You're welcome, I'm glad it worked out for you.
Don't retire TechNet! - (Don't give up yet - 13,225+ strong and growing)