Had a lower level technician try to import a large Active Directory user list of incoming freshman into a high school’s Active Directory via Powershell and mistakes were made. Basically there was no UserPrincipalName created which made logon to workstations difficult. Here is the PowerShell script used to fix the issue:
Powershell Script to Import Active Directory User List
Import-Module ActiveDirectory
$ADUsers = Get-ADUser -Filter * -SearchBase ‘OU=Employees,DC=Domain,DC=local’
foreach ($ADUser in $ADUsers) {
$GivenName = $ADUser.GivenName
$SurName = $ADUser.Surname
if (($GivenName -ne $null) -or ($SurName -ne $null))
{
$newSAM = $GivenName.Substring(0,1).ToLower() + $SurName.ToLower()
$newUPN = $newSAM + “@domain.local”
Set-ADUser $ADUser -SamAccountName $newSAM -UserPrincipalName $newUPN
Write-Host “Changes to the user $($GivenName) $($SurName) were made!”
}
}
If your company is using Active Directory User List for import or need help managing / maintaining your active directory domain, then contact us for assistance.