Set a User’s UPN in Active Directory with a Batch File

Posted by & filed under Uncategorized.

This simple batch file will modify a user’s UPN and also set first name, last name, and display name. It uses the dsquery command to pipe the required variable into dsmod. Simple and straightforward.

SET /P SAM=Sam Account Name:
SET /P UPN=New FULL UPN:
SET /P FIRST=First:
SET /P LAST=Last:

dsquery user -samid %SAM% | dsmod user -upn "%UPN%" -fn %FIRST% -ln %LAST% -display "%FIRST% %LAST%"

pause

Leave a Reply

  • (will not be published)