Solved

Verify username and password Batch Script

Posted on 2010-09-23
4
832 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

Suggested Solutions

Utilizing an array to gracefully append to a list of EmailAddresses
Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

948 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now