• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1036
  • Last Modified:

how to update UPN for all users using powershell?

Hello all,

I have a parent domain with an older UPN AAA.com. I added an alternative as AA.com in AD Domain and Trusts and after that the new users get the AA.com UPN

But I'd like to also update the older users UPN from AAA.com to AA.com, how can I do this easily with powershell?

Thanks!
0
sblanken
Asked:
sblanken
  • 3
3 Solutions
 
Krzysztof PytkoActive Directory EngineerCommented:
Please download Quest PowerShell module for AD and use this syntax. First of all test it for few users. Create a text file with usernames or run a cmd-let for all users

For users from text file

Get-content c:\users.txt | %{ Get-QADUser $_ | Set-QADUser -upn $_@aa.com }

For all users in a domain

Get-QADUser -name * -sizelimit 0 | Set-QADUser -upn $_@aa.com

Regards,
Krzysztof
0
 
sblankenAuthor Commented:
Hi, thanks for your reply. I'd like to populate the users.txt by running a script that out of 10.000 users identifies only the 1000 that still use aaa.com as UPN

I ran, for example, something like

Get-ADUser -Filter * -properties homemdb | where {$_.UserPrincipalName -gt "@aaa.com" -and $_.homemdb -ne $null}

but for some reason it shows me the @aa.com users as well, so it may be something flaky with my logic, and I don't know what that is....
0
 
chrismerrittCommented:
Maybe I am missing something, but shouldn't your query be:


Get-ADUser -Filter * -properties homemdb | where {$_.UserPrincipalName -match "@aaa.com" -and $_.homemdb -ne $null}

-gt than is used for "greater than" - I don't see how you can use that in a string operator, better for comparing numerical values, dates etc :)

Use -match for string comparison, i.e. does one string (in your case "@aaa.com") match another?
0
 
sblankenAuthor Commented:
-match is the one :)

Thanks!

splitting the points
0
 
sblankenAuthor Commented:
both experts had useful comments
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now