Pages

8/26/2022

Update AD Username Casing

 We all know that usernames in Active Directory are not case sensitive, for the most part everywhere that is the case. But I had a customer who wanted to ensure all the usernames were lowercase for reasons we shall not ask. 

Below is just one example of how you can accomplish this in PowerShell


$InformationPreference = 'Continue'

$users = Get-ADUser -Filter * -SearchBase "OU=MSHELDON,DC=T4EDEV,DC=local"

foreach($user in $users) {

    try {

            $user | Set-ADUser -Replace @{ sAMAccountName = $user.SamAccountName.ToLower() }

            Write-Information "Updated user [$($user.SamAccountName)]"

    } catch {

        Write-Warning "Failed to update user [$($user.SamAccountName)]"

    }

}

No comments:

Post a Comment