?
Solved

Verify username and password Batch Script

Posted on 2010-09-23
4
Medium Priority
?
841 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:mrfite
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
Eduardo Goicovich earned 1000 total points
ID: 33748478
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

:fail
whetever you want
exit /b %el%
0
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 33748526
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.
0
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 33748542
Ooops, that's with powershell.  belfegor has it for batch.
0
 
LVL 6

Expert Comment

by:dax_bad
ID: 33748699
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.

0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
Here's a look at newsworthy articles and community happenings during the last month.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question