<#===========================================================================================================================
Script Name: FixADNAmes.ps1
Description: This Script Does the following things.
1> Rename Active Directory User's Firstname,Lastname 1st letter to Uppercase ex: JOhn SnOw or john snOn or JOHN SNOW becomes -John Snow
2> Rename Active Directory User's samaccountname to all lower case example: Jonh becomes - john
3> Rename Active Directory User's Displayname and NAme 1st letter to Uppercase ex: JOhn SnOw or john snOn or JOHN SNOW becomes -John Snow
Inputs: OU path if Required to run on an OU
Outputs:
Notes: Run as administrator
Date Created: 08/21/2018
Credits:
Last Revised: 08/21/2018
** Instructions**
Just Launch Powershell as administrator copy the script and run or save and run it as
FixADNAmes.ps1
=============================================================================================================================#>
If ( ! (Get-module ActiveDirectory )) {
Import-Module ActiveDirectory
Clear-Host
}
Get-ADUser -filter * <#-SearchBase 'OU=OU,DC=domain,DC=Local'#>|Foreach{
$newFname=(Get-Culture).textinfo.totitlecase(($_.givenname).tolower())
$newLname=(Get-Culture).textinfo.totitlecase(($_.Surname).tolower())
$name= $newFname + ' ' + $newLname
Set-ADUser $_ -GivenName $newFname -Surname $newLname
Rename-ADObject -Id $_ -NewName $name
Set-ADUser $_.samaccountname -DisplayName $name
Set-ADUser $_.samaccountname -SamAccountName $_.SamAccountName.ToLower()
}
Clear-Host
Write-Host 'The process has been completed' -ForegroundColor Yellow
"Here is how AD users Looks now"
$newU=(Get-ADUser -filter * <#-SearchBase $ou #> -prop Displayname |Get-Random |select -First 1)
$newU |select Name,Displayname,Givenname,surname,samaccountname