Moving User/s to an OU

This is quite fun, when i say fun in the system admin life 😛
When ever you move someone out of an OU, there is an 90% chance that they could get different set of Group Policy as OU and Group policy are together.

The script below will be help you in moving.

$data = get-content -Path "usernames that needs moving file"

foreach($username in $data) {

$targetOU = "Target OU "

    $display = Get-ADUser -Properties * -LDAPFilter "(displayName=$username)" | Select samaccountname,distinguishedName
    
    $name = $display.samaccountname
    $Path = $display.distinguishedName
        try{
            Move-ADObject -Identity $display.distinguishedName -TargetPath $targetOU
            Write-Host  $name + " - Moved" -ForegroundColor Green
        
        }catch{
       
            write-host
            write-host $name + " - Not Moved" -ForegroundColor Yellow
        }
      
}

Published by iamfazul

Author of the site

Leave a comment