24. november 2011

Fixing users UserPrincipalName

We have had a scenario where some users lacked the attribute UserPrincipalName. 
To find these users I used:


$users=Get-ADUser -Server <DomainController> -filter * -searchbase "OU=Users,OU=Hosting,DC=<subdomain>,DC=<rootDomain>,DC=dk" | where {$_.userPrincipalName -eq $null}

Now to fix the attribute:


$users | foreach{$_.samaccountname;$_.UserPrincipalName = ($_.samaccountname+"@subdomain.rootdomain.dk");set-aduser -instance $_}

You can question the readability of this, but it gets the job done which is what we want.

Best regards
Claus

Ingen kommentarer:

Send en kommentar