Move list of AD users to a particular OU
# Import AD Module
import-module ActiveDirectory
# Import CSV
$MoveList = Import-Csv -Path "C:\temp\users.csv"
# Specify target OU.This is where users will be moved.
$TargetOU = "OU=Disabled Accounts,DC=us,DC=Microsoft,DC=com"
# Import the data from CSV file and assign it to variable
$Imported_csv = Import-Csv -Path "C:\temp\users.csv"
$Imported_csv | ForEach-Object {
# Retrieve DN of User.
$UserDN = (Get-ADUser -Identity $_.SamAccountName).distinguishedName
Write-Host " Moving Accounts ..... "
# Move user to target OU.
Move-ADObject -Identity $UserDN -TargetPath $TargetOU
}
Write-Host " Completed move "
$total = ($MoveList).count
Write-Host " $total accounts have been moved succesfully..."
Comments