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

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:<br /> SET /P UPN=New FULL UPN:<br /> SET /P FIRST=First:<br /> SET /P LAST=Last:

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

pause