Thanks Richard for your reply. I've used your website and vbscript
examples from there before and found them most helpful. I admit I'm
not the most proficent at scripting so I do make some beginner errors.
I changed the script to be more like what you suggested. I however
want to modify only groups in specific OUs so I changed my query to
just this OU, but it giving me errors on the 'Set objRecordSet =
objCommand.Execute' now.
Option Explicit
Dim strMailbox, strNick, strContactPath
Dim objConnection, objCommand, objRecordSet
' Section to bind to Active Directory
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "SELECT ADsPath, mailNickname " _
& "FROM 'LDAP://ou=Disabled Accounts,ou=Chicago,ou=United
States,dc=local,dc=net'" & "' " _
& "WHERE objectCategory='group'"
Set objRecordSet = objCommand.Execute
objCommand.Properties("Page Size") = 50000
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strContactPath = objRecordSet.Fields("ADsPath").Value
strNick = objRecordSet.Fields("mailNickname").value
strMailbox = "/o=Organization/ou=First Administration Group/
cn=Recipients/cn=" & strNick
Set objContact = GetObject(strContactPath)
objContact.Put "legacyExchangeDN", strMailbox
objUser.SetInfo()
objRecordSet.MoveNext
Loop
WScript.Quit
On May 21, 4:07*pm, "Richard Mueller [MVP]" <rlmueller-
nos...@xxxxxx> wrote:
> "mb" <mike.bur...@xxxxxx> wrote in message
>
> news:4b64e935-d989-490a-a8be-86d599aa3bc3@xxxxxx
>
>
>
>
>
> > Does anyone know a vbscript that will set the legacyDN value for an ou
> > using the mailNickname as the last cn name. >>
> > /o=Organization,/ou=First Administrative Group,/cn=Recipients,/
> > cn=<mailNickname> >
> > I tried this script, which runs without error, but doesn't set any
> > properties: >
> > Option Explicit
> > Dim strMailbox, strNick >>
> > ' Section to bind to Active Directory
> > Set objConnection = CreateObject("ADODB.Connection")
> > Set objCommand = CreateObject("ADODB.Command")
> > objConnection.Provider = "ADsDSOObject"
> > objConnection.Open "Active Directory Provider"
> > Set objCommand.ActiveConnection = objConnection >
> > objCommand.Properties("Page Size") = 50000 >
> > objCommand.CommandText = _
> > * *"SELECT ADsPath FROM 'LDAP://RootDSE' WHERE objectClass='group'"
> > Set objRecordSet = objCommand.Execute >
> > objRecordSet.MoveFirst
> > Do Until objRecordSet.EOF
> > * *strContactPath = objRecordSet.Fields("ADsPath").Value
> > * *strNick = objRecordSet.Fields("mailNickname").value
> > * *strMailbox = "/o=Organization/ou=First Administrative Group/
> > cn=Recipients/cn=" & strNick
> > * *Set objContact = GetObject(strContactPath)
> > * *objContact.Put "legacyExchangeDN", strMailbox
> > * *objUser.SetInfo()
> > * *objRecordSet.MoveNext
> > Loop >>
> The script runs without error messages because you use "On Error Resume
> Next". Remove this statement. Two problems I see. First, you retrieve the
> "mailNickname" attribute from the ADO recordset, but this attribute is not
> in the list of attributes. You need to add it to the list. Second, the base
> of your query is the RootDSE object. It should be a property of this object.
> I would suggest:
>
> Set objRootDSE = GetObject(LDAP://RootDSE)
> objCommand.CommandText = "SELECT ADsPath, mailNickname " _
> * * & "FROM 'LDAP://" & objRootDSE.Get("defaultNamingContext") & "' " _
> * * & "WHERE objectCategory='group'"
>
> Another problem is that you do not Dim all variables. "Option Explicit" is
> recommended, but requires that you Dim all variables. Finally, I used
> objectCategory rather than objectClass because that attribute is indexed and
> thus more efficient.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab -http://www.rlmueller.net
> --- Hide quoted text -
>
> - Show quoted text -