Link to home
Start Free TrialLog in
Avatar of mrfite
mrfiteFlag for United States of America

asked on

Verify username and password Batch Script

I am a domain Admin using a windows 2008 domain.  I have created the following batch script.



@echo off
Set /p Store=Enter the Account Name for a password reset:  

@echo You are going to attempt to change the password for %Store%'s Account.
Set /p Pass=Enter the new Password for %Store%'s Account:  
@echo off
net user %Store% %Pass% /DOMAIN



The problem is that I get no verification if the batch was successful.  I am hoping someone can help me out.  All I need is output that would verify if the username and new password work.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Eduardo Goicovich
Eduardo Goicovich
Flag of Chile image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Check the $LASTEXITCODE and see what it is when successful.  Then check when fails just to make sure it's different.  Should be able to check this for success.
Ooops, that's with powershell.  belfegor has it for batch.
How about using a vbscript instead?

Here's a link about changing passwords for AD accounts
http://www.computerperformance.co.uk/vbscript/vbscript_setpassword.htm

Alternately change the script accept arguments

strContainer = wscript.arguments.item(0)                <--- could be a single user, or entire group of users
strPassword = wscript.arguments.item(1)

As long as you leave out "On error resume next" in whatever small script you create to set the password for a user, the windows scripting Host will throw an error if it cant find the user or set pw etc.