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!”
}
}
For ideas on how to correctly import a large number users into Active Directory, look at how to format the spreadsheet and then how to write the PowerShell script at these links.
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.