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

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.

  • 2
1 Solution
Eduardo GoicovichIT ConsultantCommented:
check error level status after net function call, like this

net user %Store% %Pass% /DOMAIN

set el=%errorlevel%
if %el%==1 goto fail

exit /b 0

whetever you want
exit /b %el%
Bryan ButlerCommented:
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.
Bryan ButlerCommented:
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

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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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