Users - Move multiple users to mutiple OU from CSV file
Below script can use to move multiple users to mutiple OU from CSV file.
#Import AD Module
Import-Module ActiveDirectory
$Imported = Import-Csv -Path "C:\Users\Administrator\Desktop\Move.csv"
$Imported | ForEach-Object {
$SamAccountName = $_.SamAccountName
Enable-ADAccount -Identity $SamAccountName
# Retrieve DN of User.
$UserDN = (Get-ADUser -Identity $_.SamAccountName).distinguishedName
$TargetOU = $_.TargetOU
Write-Host " Moving Accounts ..... "
# Move user to target OU.
Move-ADObject -Identity $UserDN -TargetPath $TargetOU
}
Write-Host " Completed move "
$total = ($Imported).count
Write-Host $total "User Moved Successfully"
Comments
Post a Comment