[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1582
  • Last Modified:

DSMOD script to set Users with blank UPN to same as email address

We are trying to write a script to locate all our user accounts that do not have the UPN field populated.  Then we need to add in the UPN to be the same as the Email address of the user.  So far I have been unable to locate how to script this. Any help or input is appreciated.    
0
asburycollege
Asked:
asburycollege
  • 3
1 Solution
 
Henrik JohanssonSystems engineerCommented:
Copy code snippet into notepad and save file as *.cmd or *.bat
The script below will set UPN for all users in the domain to be e-mail address if having e-mail address set.
for /F "tokens=1,2" %%a in ('dsquery user -limit 0 ^|dsget user -samid -email^|find "@"') do (
  dsquery user -samid %%a|dsmod user -upn %%b
)

Open in new window

0
 
asburycollegeAuthor Commented:
I forgot to clarify in the original question.  We only need to have this performed on users whose UPN is currently blank.  We have some legacy users that do not have this information and some of the new technology we are implement utilizes the UPN field for authentication.  Is there a way to ONLY get and change users with a blank UPN field?
0
 
Henrik JohanssonSystems engineerCommented:
The previous script will do it if you don't have any user that UPN set, but is different to e-mail address
For example upn=jdoe@domain.com will be overidden if email=john.doe@domain.com
Modified script below to exclude those that already has UPN set to xxx@*.
To only run it on a sub-OU change the first dsquery to be
dsquery user -limit 0 "OU=OU-path,DC=domain,DC=com"
0
 
Henrik JohanssonSystems engineerCommented:
The previous script will do it if you don't have any user that UPN set, but is different to e-mail address
For example upn=jdoe@domain.com will be overidden if email=john.doe@domain.com
Modified script below to exclude those that already has UPN set to xxx@*.
To only run it on a sub-OU change the first dsquery to be
dsquery user -limit 0 "OU=OU-path,DC=domain,DC=com"
for /F "tokens=1" %%a in ('dsquery user -limit 0 ^|dsget user -samid -upn^|find /v "@"') do (
  for /F "tokens=1,2" %%u in ('dsquery user -samid %%a ^|dsget user -samid -email^|find "@"') do (  
    dsquery user -samid %%a|dsmod user -upn %%v
  )
)

Open in new window

0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

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