Powershell批量修改用户的UPN后缀
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 [email protected]
Guest Guest [email protected]
krbtgt krbtgt [email protected]
Exchange Online-ApplicationAccount $331000-K0SAH4NCDJ2K [email protected]
以上是关于Powershell批量修改用户的UPN后缀的主要内容,如果未能解决你的问题,请参考以下文章