Powershell批量修改用戶的UPN後綴

適用產品:Windows Server ActiveDirectory
查詢AD中UPN爲空的用戶
Get-ADUser -Filter * -Properties * | where {$_.UserPrincipalName -eq $null} | Select-Object name,SamAccountName,UserPrincipalName
設置UPN後綴
Get-ADUser -Filter * -Properties * | where {$_.UserPrincipalName -eq $null} | Select-Object name,SamAccountName,UserPrincipalName | foreach {Set-ADUser -Identity $_.name -UserPrincipalName ($_.SamAccountName+"@contoso.com")}
查詢結果
PS C:\Users\Administrator> Get-ADUser -Filter * -Properties * | where {$_.UserPrincipalName -eq $null} | Select-Object name,SamAccountName,UserPrincipalName

name                       SamAccountName             UserPrincipalName        
----                       --------------             -----------------        
Guest                      Guest                                               
krbtgt                     krbtgt                                              
mailuser2                  mailuser2                                           
mailuser3                  mailuser3                                           
mailuser4                  mailuser4                                           
mailuser5                  mailuser5                                           
mailuser6                  mailuser6                                           
mailuser7                  mailuser7                                           
mailuser8                  mailuser8
設置結果
Get-ADUser -Filter * -Properties * | where {$_.UserPrincipalName -ne $null} | Select-Object name,SamAccountName,UserPrincipalName
name                                                        SamAccountName                                              UserPrincipalName                                         
----                                                        --------------                                              -----------------                                         
Administrator                                               Administrator                                               Administrator@demo.com                                    
Guest                                                       Guest                                                       Guest@demo.com                                            
krbtgt                                                      krbtgt                                                      krbtgt@demo.com                                           
Exchange Online-ApplicationAccount                          $331000-K0SAH4NCDJ2K                                        Exchange_Online-ApplicationAccount@demo.com
相關文章
相關標籤/搜索