Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How to use a VBScript to write proxy addresses to an Ldifde.exe-compatible import file in Exchange Server 2003


View products that this article applies to.

Introduction

This article discusses how to use a Microsoft Exchange Server 2003 VBScript that performs the following operations:
Connects to the default naming context in the Active Directory directory service
Extracts e-mail proxy addresses
Writes the proxy addresses to an Ldifde.exe-compatible import file
This script can be used to back up and to restore e-mail proxy addresses for objects that are defined as exempt from the Exchange Server Recipient Update Service. This script can also restore e-mail proxy addresses that were not generated by the Recipient Update Service.

↑ Back to the top


More information

To use the VBScript, follow these steps:
1.Open a text editor, copy the following text to a new file, and then save the new file as Proxydump.vbs.
' --- Start script ---

'
' This script will connect to your default naming context 
' in Active Directory and build an ldifde.exe import file
' for all users and their e-mail addresses.
' The default file name is userProxyAddresses.ldf
'
' -------------------------------------------------------
' 
' Copyright (C) 2006 Microsoft Corporation
' You have a royalty-free right to use, modify, 
' reproduce and distribute this sample application
' (or any modified version) in any way you find useful,
' provided that you agree that Microsoft has no warranty, 
' obligations or liability for results produced by this or
' your sample application.
'
' ---------------------------------------------------------
Dim exportFileName
Dim count
Dim FileObject
Dim LogFile
Dim Connection
Dim Command
Dim RecordSet
 
Const Writable = 2
exportFileName = InputBox("Enter an name for the ldifde import file;" & _
" .ldf will be added to the file name.", "e-mail address import generator",_
"userProxyAddresses")
count = 0 

Set FileObject   = CreateObject("Scripting.FileSystemObject")
Set LogFile                          = FileObject.OpenTextFile(exportFileName & _
".ldf", Writable, True)
Set Connection  = CreateObject("ADODB.Connection")
Set Command                   = CreateObject("ADODB.Command")
Set RecordSet   = CreateObject("ADODB.RecordSet") 

With Connection
                .Provider             = "ADsDSOObject"
                .Open "Active Directory Provider"
End With

Set Command.ActiveConnection = Connection
Set objRootDSE = GetObject("LDAP://rootDSE")
Command.CommandText = "<LDAP://" & _
objRootDSE.Get("defaultNamingContext")_
& ">;(&(objectCategory=user)(proxyAddresses=*))" & _
";distinguishedName,mail,proxyAddresses;subtree" 

Set RecordSet   = Command.Execute 

While Not RecordSet.EOF

                On Error Resume Next
                strUserDN                           = RecordSet.Fields("distinguishedName")
                strMail                                  = RecordSet.Fields("mail")
                strProxyAddress = RecordSet.Fields("proxyAddresses")
 
                LogFile.Write "dn: " & strUserDN & vbCrLf
                LogFile.Write "changetype: modify" & vbCrLf
                LogFile.Write "replace: mail" & vbCrLf
                LogFile.Write "mail: " & strMail & vbCrLf
                LogFile.Write "-" & vbCrLf & vbCrLf 

                LogFile.Write "dn: " & strUserDN & vbCrLf
                LogFile.Write "changetype: modify" & vbCrLf
                LogFile.Write "replace: proxyAddresses" & vbCrLf

                For Each Item in strProxyAddress
                                strTempAddr = Item
                                LogFile.Write "proxyAddresses: " & Item & vbCrLf
                    count = count + 1
                Next

                LogFile.Write "-" & vbCrLf & vbCrLf

                RecordSet.MoveNext

Wend

LogFile.Close

msgbox "Exported " & count & " users and " & _
"their e-mail addresses to " _
& exportFileName & ".ldf" 

Set objRootDSE  = Nothing
Set FileObject   = Nothing
Set LogFile          = Nothing
Set Connection = Nothing
Set Command   = Nothing
Set RecordSet   = Nothing
� --- end script --- 
2.Locate and then double-click the file that you saved.
3.Enter the name of the Ldifde import file, and then click OK. The default name for this file is UserProxyAddresses.ldf.

Note Ldifde.exe is a command-line tool that imports and exports Active Directory information. Ldifde.exe is included in Microsoft Windows Server 2003 and in Microsoft Windows 2000 Server.
4.When the script is completed, a message is displayed that includes the number of users whose e-mail proxy addresses were exported. The Ldifde import file is ready to be imported.
5.To import the UserProxyAddresses.ldf file, follow these steps:
a. Click Start, click Run, type cmd in the Open box, and then click OK.
b. Change to the drive location in which the script was saved.
c. Type ldifde -i -f userProxyAddresses.ldf, and then click OK.
d. When the command succeeds, close the command prompt.
For more information about how to use the Ldifde.exe command-line tool, click the following article number to view the article in the Microsoft Knowledge Base:
237677 Using LDIFDE to import and export directory objects to Active Directory
For more information about Ldifde.exe, visit the following Microsoft Web site: For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
328738 How the Recipient Update Service applies recipient policies
820381 The secondary SMTP proxy e-mail address is not stamped on migrated objects
821743 The gatewayProxy attribute on the Recipient Update Service object is not cleared

↑ Back to the top


Keywords: KB922258, kbinfo, kbhowto, kbdirectory

↑ Back to the top

Article Info
Article ID : 922258
Revision : 3
Created on : 10/25/2007
Published on : 10/25/2007
Exists online : False
Views : 255