none
How to move AD user accounts to a specified OU from CSV file RRS feed

  • Question

  • 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

    Wednesday, March 11, 2015 12:48 AM

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
    Wednesday, March 11, 2015 4:25 AM

All replies