SID-500

Home » PowerShell » PowerShell: Changing Active Directory user logon names (Bulk)

PowerShell: Changing Active Directory user logon names (Bulk)

Active Directory users log on with their logon names and password. But what are the rules for assigning usernames? g.surname? surname? gsurname? What are the naming conventions? This article looks for and modifies users who do not meet the naming convention.

Searching for logon names that do not match the naming convention

For the following it is assumed that you use a naming convention of g.surname for all newly created users (Patrick Gruenauer = p.gruenauer). So, we have to search for usernames that don’t have a dot (.). Here’s one:

4.JPG

Now we are looking for users in a particular Organizational Unit (People) that do not meet the naming convention.

Get-ADUser -Filter {SamAccountName -NotLike "*.*"} -Searchbase "OU=People,DC=SID-500,DC=COM" | Select-Object Name,SamAccountName,Userprincipalname

Unbenannt.JPG

Check the list carefully. In the next step we will start modifying their SamAccountName and Userprincipalname.

Changing user logon names

Now we are going to replace the SamAccountName and the UserprincipalName with the first letter of the givenname followed by . and the lastname in lower case.

Get-ADUser -Filter {(SamAccountName -NotLike "*.*") -and (UserprincipalName -notlike "*.*@*")} -SearchBase "OU=People,DC=SID-500,DC=COM" | Foreach-Object {Set-ADUser $_ -SamAccountName ($_.givenname.substring(0,1) + '.' + $_.surname).tolower() -UserPrincipalName (($_.givenname.substring(0,1) + '.' + $_.surname).tolower() + "@" + "$env:userdnsdomain")}

3.JPG

Schwarzenberg then becomes a.schwarzenberg:

3.JPG

Last but not least

Don’t forget to inform the users! 😉


5 Comments

  1. […] PowerShell: Changing Active Directory user logon names (Bulk) […]

    Like

  2. […] PowerShell: Changing Active Directory user logon names (Bulk) […]

    Like

  3. […] PowerShell: Changing Active Directory user logon names (Bulk) […]

    Like

  4. […] PowerShell: Changing Active Directory user logon names (Bulk) […]

    Like

  5. […] PowerShell: Changing Active Directory user logon names (Bulk) […]

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

WHOIS

My name is Patrick Grünauer (pewa2303). I am from Austria. On sid-500 I write about Windows, Cisco and IT-Security in English and German. Have fun while reading!

Patrick Gruenauer
Follow SID-500 on WordPress.com