Applicable product: Windows Server activedirectory queries the user for a blank UPN in AD
Get-ADUser -Filter * -Properties * | where {$_.UserPrincipalName -eq $null} | Select-Object name,SamAccountName,UserPrincipalName
Set the UPN suffix
Get-ADUser -Filter * -Properties * | where {$_.UserPrincipalName -eq $null} | Select-Object name,SamAccountName,UserPrincipalName | foreach {Set-ADUser -Identity $_.name -UserPrincipalName ($_.SamAccountName+"@contoso.com")}
Query results
PS c:\users\administrator> get-aduser-filter *-properties * | where {$_. Userprincipalname-eq $null} | Select-object name,samaccountname,userprincipalnamename sAMAccountName userPrincipalName -----------------------------------Guest Guest KRBTGT krbtgt Mailuser2 Mailuser2 Mailuser3 Mailuser3 Mailuser4 Mailuser4 Mailus Er5 Mailuser5 Mailuser6 Mailuser6 Mailuser7 Mailuser7 Mailuser8 Mailuser8
Set results
Get-aduser-filter *-properties * | where {$_. Userprincipalname-ne $null} | Select-object Name,samaccountname,userprincipalnamename SAMACCOUNTN Ame userPrincipalName---- -------------- ----------------- Administrator Administrator [Email protected] Guest Guest [E Mail protected] Krbtgt krbtgt [email protected] Exchange Online-applicationaccount $331000-k0sah4ncdj2k [Email protected]
PowerShell bulk Modifies a user's UPN suffix