• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

80005000 Error trap

D

Dave Susemiehl

#1
Hi, I can muddle through scripting ok most of the time but I'm not sure how
to handle this.

So here's my dilemma, I want to use a text file for the OU's and Groups to
create in the OU's. I read them into an array ok so I have them available
but obviously each OU contains multiple groups. If I just cycle through the
Array Creating the OU's I will quickly run into an already exists error. I
couldn't find a good way to do an if exists on OU's so I decided to try to
get the OU and if it errors the script would create the ou. The nice simple
GET line looks something like this:

Set mkOU = GetObject("LDAP://OU=" & arrOU(0) & ",OU=parentOU," & DomainPath)
---This line gets the desired results

And then do an error trap so that if the 80005000 error is encounter It
creates the OU.

Any help would be appreciated.
 

My Computer

R

Richard Mueller [MVP]

#2
"Dave Susemiehl" <Dave Susemiehl@xxxxxx> wrote in message
news:1F154E09-C841-43D7-A182-D17A802B050B@xxxxxx

> Hi, I can muddle through scripting ok most of the time but I'm not sure
> how
> to handle this.
>
> So here's my dilemma, I want to use a text file for the OU's and Groups to
> create in the OU's. I read them into an array ok so I have them available
> but obviously each OU contains multiple groups. If I just cycle through
> the
> Array Creating the OU's I will quickly run into an already exists error.
> I
> couldn't find a good way to do an if exists on OU's so I decided to try to
> get the OU and if it errors the script would create the ou. The nice
> simple
> GET line looks something like this:
>
> Set mkOU = GetObject("LDAP://OU=" & arrOU(0) & ",OU=parentOU," &
> DomainPath)
> ---This line gets the desired results
>
> And then do an error trap so that if the 80005000 error is encounter It
> creates the OU.
>
> Any help would be appreciated.
>
Use "On Error Resume Next" to suppress normal error handling (which aborts
the script). Then you can test the Err object for error number and
description. Use "On Error GoTo 0" to restore normal error handling (this
also clears the Err object). For example:
========
On Error Resume Next
Set mkOU = GetObject("LDAP://ou=" arrOU(0) & ",ou=parentOU," & DomainPath)
If (Err.Number <> 0) Then
' Error raised attempting to bind the OU.
' Display error information (optional).
Wscript.Echo "Error binding to OU " & arrOU(0)
Wscript.Echo "Error Number: " & Err.Number
Wscript.Echo "Description: " & Err.Description
Wscript.Echo "Source: " & Err.Source
On Error GoTo 0
' Create the OU.
' ...
Else
On Error GoTo 0
' The OU must already exist
End If
=========
If you know the specific error number you want to trap, you can test for
that. However, Err.Number will be decimal, while 80005000 is hex, so you
will need to convert. Best to test and see what Err.Number returns (some are
negative). I find Err.Number is -2147016656 when I attempt to bind to a
non-existent OU. If I have an invalid character (invald DN format) I
get -2147016654. Might be best just to test if Err.Number is non-zero.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
 

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)