PowerShell bulk modifies the user's UPN suffix

Source: Internet
Author: User
Tags samaccountname

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.