Reputation: 353
I have some users in AD that have the UPN address set like [email protected]
. I want to change those users so their UPN looks like that [email protected]
.
I have written a PS line to find me such users:
Get-ADUser -LDAPFilter "(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2)(userPrincipalName=*@this.org))" -SearchBase "OU=this,DC=that" | Select SamAccountName
But how do I update those users. I know about Set-AdUser
command, but I can't figure out how to feed the result of the Get-Aduser
into it.
Upvotes: 1
Views: 1562
Reputation: 3046
Just pipe it to Set-ADUser
:
Get-ADUser -LDAPFilter "(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2)(userPrincipalName=*@this.org))" -SearchBase "OU=this,DC=that" | % {Set-ADUser $_ -UserPrincipalName "that"}
Just a heads up, use -Whatif
during testing before you crash you whole AD.
Explanation:
%
- Alias for foreach
$_
- Equals each object of the foreach
(each User found in the Get-ADuser
)
-UserPrincipalName "that"
- Set the UPN of the given User to that
Upvotes: 5