Discussion Locked

Windows Scripting Error Handling

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I'm writing a script that will create users in Active Directory. The script runs OK and does what I want it to, but I'm trying to report any errors to a text file.

See Sample extract below, using arrInput variables:

Set objUser = objOU.Create("User", "cn=" & arrInput(1))
objUser.Put "sAMAccountName", arrInput(1)
objUser.Put "userPrincipalName", arrInput(1) & "@hcctest.gov.uk"
objUser.SetInfo

If Err.Number = 0 Then
f.Write arrInput(4) & " - " & Err.Number & " - " & Err.Description f.WriteBlankLines(1)
Err.Clear
f.close
Else
'wscript.echo arrInput(4) & " Created successfully"
f.Write arrInput(4) & " Created successfully"
f.WriteBlankLines(1)
f.Close
End If

1 reply

by andybonner

Dim fso
Set fso=WScript.CreateObject("Scripting.FileSystemObject")
Set outfile=fso.CreateTextFile("F:\" & "myFile.txt")
outfile.writeline("'Whatever you want to write'")
outfile.close

This discussion is closed to new replies.