Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error reporting

Status
Not open for further replies.

DECNET

Technical User
Apr 28, 2001
56
0
0
GB
I have the following script, to reset the Administrator password based on membership of an OU.

However, I would like to report a success or failure when the script connects to the computer.

I added the 'On Error Resume Next' line to avoid the errors, but I can't see the progress of the script.

What would I have to add to this script to achieve this?

Simple reporting would be fine, a TXT file etc.

Set objOU = GetObject("LDAP://OU=TestOU, DC=Fabrikam, DC=com")
objOU.Filter = Array("Computer")

On Error Resume Next

For Each objItem in objOU

strComputer = objItem.CN
Set objUser = GetObject("WinNT://" & strComputer & "/Administrator")

objUser.SetPassword("********")

Next

MsgBox "The script has finished"

Many thanks

DEC

If it helps, let me know, if it doesn't, let me know. It's the only way I'll learn.
 
Hello Clifford,

If you want to track .setpassword error specifically, you can do this checking error object and tightening the positioning of the "on error resume next" statement.
[tt]
Set objOU = GetObject("LDAP://OU=TestOU, DC=Fabrikam, DC=com")
objOU.Filter = Array("Computer")

For Each objItem in objOU

strComputer = objItem.CN
Set objUser = GetObject("WinNT://" & strComputer & "/Administrator")
[green]
on error resume next
objUser.SetPassword("********")
if err.number<>0 then
wscript.echo " Error : " & hex(err.number) & vbcrlf & err.description & vbcrlf & _
"User : " & objUser.fullname & " password has not been reset."
err.clear
end if
on error goto 0
[/green]
Next

MsgBox "The script has finished"
[/tt]
I deliberately put on error resume next under set objUser and within the loop. This config will trap exactly the error arisen from .setpassword statement and leave the script error out due to some other reason.

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top