Istanbul/Turkey

Move User Accounts to another OU based on department info from CSV

Greetings!

Today I will to move the existing Active Directory user accounts from their OU to another OU based on the users' department information from a csv file. 

 

 

$Imported = Import-Csv -Path "C:\move.csv" 
$Imported | ForEach-Object {
     # Retrieve DN of User.
     $CurrentDN  = (Get-ADUser -Identity $_.Username).distinguishedName
     $TargetOU = $_.TargetOU
     Write-Host "Moving Account: " $_."Username"
     # Move user to target OU.
     Move-ADObject  -Identity $CurrentDN  -TargetPath $TargetOU
     
 }
 $total = ($Imported).count
 Write-Host $total "User Moved Successfully"

 

 

 

  • Hits: 3695