Solved

Verify username and password Batch Script

Posted on 2010-09-23
4
835 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
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
Eduardo Goicovich earned 250 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Introduction You may have a need to setup a group of users to allow local administrative access on workstations.  In a domain environment this can easily be achieved with Restricted Groups and Group Policies. This article will demonstrate how to…
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 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