نمایش نتایج: از شماره 1 تا 5 از مجموع 5
سپاس ها 4سپاس
  • 1 توسط patris1
  • 1 توسط patris1
  • 1 توسط patris1
  • 1 توسط patris1

موضوع: Global or Universal Contact

  
  1. #1
    mkm
    mkm آنلاین نیست.
    نام حقيقي: \\/\// K \\/\//

    عضو عادی شناسه تصویری mkm
    تاریخ عضویت
    Feb 2008
    محل سکونت
    The city of Tehran
    نوشته
    919
    سپاسگزاری شده
    385
    سپاسگزاری کرده
    253

    Icon14 Global or Universal Contact

    سلام به دوستان

    من میدونم که میشه برای اطلاعات شخص New Contact درست کرد ولی
    چطور میشه در سرور 2003 یک Contact List درست کرد که تمام اطلاعات کارمندان داخلش باشه. مثل شماره داخلی و ایمیل و .... که کارمندان بتونن با سرچ در Active directory اون لیست رو باز کنن. آیا راهی هست که تمام اطلاعات روی یک فایل باشه؟؟؟؟؟



    موضوعات مشابه:

  2. #2
    نام حقيقي: 1234

    مدیر بازنشسته
    تاریخ عضویت
    Jul 2009
    محل سکونت
    5678
    نوشته
    5,634
    سپاسگزاری شده
    2513
    سپاسگزاری کرده
    272
    کد:
    http://www.msexchange.org/articles/Migrating-Contacts-Distribution-Lists-Outlook-Active-Directory.html

    Migrating Contacts and Distribution Lists from Outlook to Active Directory

    Use script magic to turn your Outlook MAPI based contact information to a lightening fast Active Directory, Exchange enhanced LDAP implementation

    Introduction

    In my article "Using Exchange 2000 as a low end contact management solution" I presented a way of using Active Directory to search for contacts. Active Directory, once it is extended by Exchange, provides a scalable solution for looking up contacts using the LDAP protocol. Resolving contact names using Outlook when accessing Active Directory is really fast, even if you have hundreds of contacts, and doesn't slow down the way it does when you have too many contacts in an Outlook contacts public folder.
    On the other hand Outlook contacts folders are really easy to use. You can import information from a lot of sources using the Import and Export wizard without much hassle. Any application which supports exports of its contacts to a text file can be exported to Outlook because you can always rearrange the contact field to match those of Outlook.
    While Active Directory provides the LDIFDE and CSVDE utilities for importing bulk information, they are not really the easiest conversion utilities that one could hope for.
    I will present here some useful scripts for migrating contacts from Outlook to Active Directory. For you, it can be a two part process. For example, if you need to migrate 70,000 contacts from Outlook Express, you can first export them to Outlook, and then use my scripts to transport them to Active Directory.


    Contact Migration Script

    My script, written in VBScript language has the following requirements. It assumes you've placed the contacts in a Public Folder named "Company Contacts", but you can change the line that begins with "Set myfolder = myNameSpace.Folders" to point to whichever Outlook folder suits you.
    You will need to change the line that begins with "Set objContainer =" so that it will point to an existing Organization Unit (OU) where the Contacts will be placed. To do this, replace the part that says "OU=….,DC=…." with the distinguishedName attribute of the OU. This property can be found by using the support tools utility ADSIEdit.
    For the script to work properly you would also require the "countrycodes.csv" file downloaded here. This file allows Active Directory to register a contact's country with its country code.
    The script goes through all the contacts in the Public Folder, checks to see whether the contact already exists and if not creates the contact. It goes through all the contact fields and if a contact property exists it is translated to its Active Directory equivalent.
    A couple of issues came up while writing this script. The main one was what to do with duplicate contacts, or contacts with same name. The primary check is to see whether the e-mail address exists. If it does not and the contact name already exist (as determined by the DNExists function), the company name is added to the directory name of the new contact.
    The script migrates only the business address. You can customize the script to add the home address but know that the Active Directory Users and Computers snap-in does not show this address at this point.

    کد:
    ContactMigationScript.vbs  
    Dim objRecip 
    'On Error Resume Next
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set myOlApp = CreateObject ("Outlook.Application")
    Set myNameSpace = myOlApp.Application.GetNamespace("MAPI")
    'Get the Public Folder containing the contacts
    Set myfolder = myNameSpace.Folders("Public Folders"). _
          Folders("All Public folders").Folders("Public Contacts")
    'Open a test file for reporting putposes
    Set reportfile = fs.CreateTextFile ("c:\contactreport.txt")
    'Look for all contacts in the Public Folder
    For I = 1 To myfolder.Items.Count
       If TypeName(myfolder.Items.Item(I)) = "ContactItem" Then
                  Set outlookcontact = myfolder.Items(I)
    'Fix the FileAs field so it won't contain Linefeeds.
              FixedFileAs = Replace (outlookcontact.FileAs,Chr(13)," - ")
    'Get the Public Contacts OU
              Set objContainer = GetObject(LDAP://OU=Public Contacts,DC=company,DC=com)
              TestforContact = False
    'Check to see if the e-mail address already exists
              For Each adcontact In objContainer
                  If (CStr (outlookcontact.Email1Address) <> "") And _
                    (CStr(adcontact.mail) = CStr (outlookcontact.Email1Address)) Then _
                     TestforContact = True
    'Check to see whether this is a new contact with an existing name, but from a different company
                   If  (CStr (adcontact.displayName) = FixedFileAs) And _
                      (CStr (outlookcontact.CompanyName) = CStr (adcontact.company)) Then _ 
                      TestforContact = True
                  Next
    'Create a valid directory name for the contact. 
             CNName = "CN=" & outlookcontact.FullName
             stAddCompany = ""
             If DNExists (CNNAME) Then
                   If outlookcontact.CompanyName = "" Then
                     TestforContact = True 
                   Else  
    'If the directory name exists add the company name to it.
                 CNName = "CN=" & outlookcontact.FullName & " (" & outlookcontact.CompanyName &  ")"
                 If DNExists (CNNAME) Then TestforContact = True
                End If           
             End If             
               If TestforContact = False then 
                         ' Create a Contact
                          Reportfile.WriteLine "Creating: " & FixedFileAs
                             Set objContact = objContainer.Create("contact", CNName)
                           ' Now fill the contact attributes in Active Directory
                            With objContact
                                  .Put "displayName", FixedFileAs
                            If outlookcontact.LastName <> "" Then _
                                 .Put "sn",CStr(outlookcontact.LastName)
                                       If outlookcontact.FirstName <> "" Then _
                                 .Put "givenName",CStr(outlookcontact.FirstName)
                                       If outlookcontact.CompanyName <> "" Then _ 
                                        .Put "company" , CStr(outlookcontact.CompanyName)
                                       If outlookcontact.Department <> "" Then _ 
                                        .Put "department" , CStr(outlookcontact.department)
                                    If outlookcontact.BusinessAddressCity <> "" Then _
                                        .Put "l", CStr(outlookcontact.BusinessAddressCity)
                                      If outlookcontact.Title <> "" Then _ 
                                        .Put "title", CStr(outlookcontact.Title)
                                      If outlookcontact.WebPage <> "" Then _
                                 .Put "wWWHomePage", CStr(outlookcontact.WebPage)
                                      If outlookcontact.Department <> "" Then _
                                        .Put "department" , CStr(outlookcontact.Department)
                                      If outlookcontact.BusinessAddressStreet <> "" Then _ 
                                  .Put "streetAddress" , CStr(outlookcontact.BusinessAddressStreet)
                                      If outlookcontact.BusinessAddressPostOfficeBox <> "" Then _
                                  .Put "postOfficeBox" , CStr(outlookcontact.BusinessAddressPostOfficeBox)
                               If outlookcontact.BusinessAddressPostalCode <> "" Then _
                                  .Put "postalCode" , CStr(outlookcontact.BusinessAddressPostalCode)
                               If outlookcontact.BusinessAddressState <> "" Then _ 
                                  .Put "st" , CStr(outlookcontact.BusinessAddressState)
                               If outlookcontact.BusinessAddressCountry <> "" Then 
                                        .Put "co", CStr(outlookcontact.BusinessAddressCountry)
    'Open a file containing table of Country Name, Country designation (two characters) and Country Code
    '(Numberical code like the one used for dialing)
                                        Set codes = fs.OpenTextFile("c:\countrycodes.csv")
                                        Do While not codes.AtEndOfStream
                                          countryst = codes.ReadLine
                                          countryar = Split (countryst,",")
                                          If countryar(0)= CStr(outlookcontact.BusinessAddressCountry) Then
                                              .Put "c",  countryar (1)
                                             .Put "countryCode", CInt(countryar(2))
                                          End If
                                        Loop 
                                   End If
                               If outlookcontact.BusinessTelephoneNumber <> "" Then _
                                .Put "telephoneNumber" ,  CStr(outlookcontact.BusinessTelephoneNumber)
                               If outlookcontact.HomeTelephoneNumber <> "" Then _
                                .Put "homephone" ,  CStr(outlookcontact.HomeTelephoneNumber)
                               If outlookcontact.PagerNumber <> "" Then _ 
                                .Put "pager" , CStr(outlookcontact.PagerNumber)
                               If outlookcontact.MobileTelephoneNumber <> "" then _
                                .Put "Mobile", CStr(outlookcontact.MobileTelephoneNumber)
    'Create the mailNickname (alias) attribute from the e-mail and mail-enable the contact.
                               If outlookcontact.Email1Address <> "" Then
                                       Set objRecip = objContact
                                       TempAr = Split (outlookcontact.Email1Address,"@")
                                       objRecip.mailNickname = TempAr (0) & "at" & TempAr (1)
                                       FwdAddress = "SMTP:" & outlookcontact.Email1Address
                                       objRecip.MailEnable FwdAddress
                               End If 
                               .SetInfo
                       End With
               Else
                  Reportfile.WriteLine "Ignoring " & FixedFileAs 
              End If
           End If
    Next 
     Reportfile.close 
     Function DNExists (dn)
    'Determines if a directory name exists by querying Active Directory using LDAP 
            DNExists = False 
            Set rootDSE=GetObject(LDAP://RootDSE)
            DomainContainer = rootDSE.Get("defaultNamingContext")
            Set conn = CreateObject("ADODB.Connection")
            conn.Provider = "ADSDSOObject"
            conn.Open "ADs Provider"
            ldapStr = "<LDAP://" & DomainContainer & ">;(& (cn=" & Mid (dn,4)  & ") );adspath;subtree"
            Set rs = conn.Execute(LDAPStr)
            If rs.RecordCount = 1 Then DNExists = True
            conn.Close
    End Function

    The most important and somewhat tricky property of them all is the e-mail address. In Active Directory, a contact is assigned a single e-mail address. It is also assigned an Exchange "alias", now called "mailNickname". This property has no real functionality for contacts but it has to be unique in Active Directory for the contact to be created. In the script I create this property by replacing the "@" symbol with the word "at" but it can be any other unique name.
    This script cannot migrate more than the first e-mail. A contact needs to be stamped by Exchange before you can add more e-mail addresses, so I provide a second script which should be run after the Exchange RUS has been fired, which usually happens in a range of fifteen minutes after running the contact migration script.
    The second script goes through all the contacts in the Public Folder looks for a matching Exchange stamped contact created earlier and adds the e-mail address. Outlook supports three e-mail addresses per contact but I assumed two will suffice. If you need all three e-mail addresses, simply change the field "Email2Address" to "Email3Address" and run the script again.


    کد:
    Dim objRecip
        Dim mycontact' As ContactItem
        Dim proxies
        'On Error Resume Next
        Set rootDSE=GetObject(LDAP://RootDSE)
        DomainContainer = rootDSE.Get("defaultNamingContext")
    'Open a connection to the Public Contacts public folder
        Set myOlApp = CreateObject("Outlook.Application")
        Set myNameSpace = myOlApp.Application.GetNamespace("MAPI")
        Set myfolder = myNameSpace.Folders("Public Folders"). _
            Folders("All Public folders").Folders("Public Contacts")
    'Open a connection to Active Directory
        Set conn = CreateObject("ADODB.Connection")
       conn.Provider = "ADSDSOObject"
       conn.Open "ADs Provider"
    'Run through all the contacts in the public folder
        For I = 1 To myfolder.Items.Count
            If TypeName(myfolder.Items.Item(I)) = "ContactItem" Then
                Set mycontact = myfolder.Items(I)
    ' If a contact has a second e-mail address find the first contact in Active Directory
    ' by using the first e-mail address      
                If (mycontact.Email2Address <> "") Then
                    LDAPStr = "<LDAP://" & DomainContainer & _ 
                      ">;(&(objectCategory=contact)(mail=" _
                      & mycontact.Email1Address & "));adspath;subtree"
                     Set rs = conn.Execute(LDAPStr)
                     If rs.RecordCount = 1 Then
                         Set oContact = GetObject(rs.Fields(0).Value)
                         Set objRecip = oContact
    'Add the second e-mail address to the contact if it is njot already a property of the contact
                          sAddress = "smtp:" & mycontact.Email2Address 
                           bIsFound = False
                           vProxyAddresses = objRecip.ProxyAddresses
                           nProxyAddresses = UBound(vProxyAddresses)
                           nProxyAddress = 0
                           Do While nProxyAddress <= nProxyAddresses
                                          If vProxyAddresses(nProxyAddress) = sAddress  Then
                                            bIsFound = True
                                            Exit Do
                                          End If
                                          nProxyAddress = nProxyAddress + 1
                           Loop
                           If Not bIsFound Then
                             ReDim Preserve vProxyAddresses(nProxyAddresses + 1)
                              vProxyAddresses(nProxyAddresses + 1) = sAddress
                              objRecip.ProxyAddresses = vProxyAddresses
                              oContact.SetInfo
                           End If 
                     End If
                 End If
            End If
        Next
        conn.Close

    Converting Distribution Lists

    Distribution lists are a very weak link in Outlook. Since Outlook is not really a directory per-se like Active Directory, there is usually some problem with keeping track of where the contacts that belong to the Distribution List exist. Also, when you do an import or export the reference to the contacts is deleted and all that is left is the e-mail address of the contact which is not updated.
    Converting the Distribution list requires to create a Universal Distribution Group in Active Directory for each Distribution List and then look for the contacts that already exist in Active Directory, searching according to their e-mail address.


    کد:
    Dim MyDl
        Dim objRecip
        Dim mailar(2)
       ' On Error Resume Next 
        Set rootDSE=GetObject(LDAP://RootDSE)
        DomainContainer = rootDSE.Get("defaultNamingContext")
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set userFile = fs.CreateTextFile("c:\DLConvertReport.txt")
        Set myOlApp = CreateObject("Outlook.Application")
        Set myNameSpace = myOlApp.Application.GetNamespace("MAPI")
    'Open a connection to the DLs public folder.
        Set myfolder = myNameSpace.Folders("Public Folders"). _
            Folders("All Public folders").Folders("DLs")
         FindContactinDLs = False
    'Go through all the distribution lists in the folder
        For I = 1 To myfolder.Items.Count
            If TypeName(myfolder.Items.Item(I)) = "DistListItem" Then
                 Set MyDl = myfolder.Items(I)
    '  Set the Type of Group as Universal Distribution Group 
                  lGroupType = &H8 'ADS_GROUP_TYPE_UNIVERSAL_GROUP
    ' Create the Group
                  Set objContainer = GetObject(LDAP://OU=DLs,DC=company,DC=com)
                 strGroupName = MyDl.DLName
     Set iAdGroup = objContainer.Create("group", "cn=" + strGroupName)
    ' Create a login name for the group that conforms to the NT4 standards
                 strSamAcctName = "DL" & Replace(strGroupName, " ", "")
                 strSamAcctName = Left(strSamAcctName, 12)
    'Add a number at the end of login name of the group if it exists
                n = 2
                 If LoginNameExists (strSamAcctName) Then _
                      strSamAcctName = strSamAcctName & "2"  
                 Do While LoginNameExists (strSamAcctName) 
                   n = n + 1
                   strSamAcctName = Left (strSamAcctName,12) & CStr (n)
                 Loop
                 iAdGroup.Put "sAMAccountName", strSamAcctName
                 iAdGroup.Put "groupType", lGroupType
                 userFile.WriteLine "Creating   " & strGroupName
    ' Flush to the directory
                 iAdGroup.SetInfo
     'Mail Enable 
                 Set iMailGroup = iAdGroup
                 iMailGroup.mail = strSamAcctName & "@company.com"
                 iMailGroup.MailEnable
     ' Write Exchange information to the directory.
                 iAdGroup.SetInfo
    ' Look for members of the distribution list in Active Directory
                 For y = 1 To MyDl.MemberCount
                      Set DLMember =  MyDl.GetMember(y)
                     WScript.Echo DLMember.Name & "  " & DLMember.Address 
                      If DLMember.Address <> "" Then
                                   contactMail = MyDl.GetMember(y).Address
                                   recipient = 
                                   Set conn = CreateObject("ADODB.Connection")
                                   conn.Provider = "ADSDSOObject"
                                   conn.Open "ADs Provider"
                                    ldapStr = "<LDAP://" & DomainContainer & _ 
                                       ">;(&(&(objectCategory=contact)(!extensionAttribute1=ShowInGAL)" & _
    "(&(&(& (| (&(objectCategory=person)(objectClass=contact))" & _
    ")))(objectCategory=contact)(proxyAddresses=smtp:" & _
    CStr(contactMail) & "))));adspath;subtree"
                                     Set rs = conn.Execute(ldapStr)
     'If contact is found add it to the corresponding Universal Group           
                                     If Not rs.EOF Then
                                        Set oContact = GetObject(rs.Fields(0).Value)
                                        path = oContact.ADsPath
                                        If Not (iAdGroup.IsMember(path)) Then
                                            userFile.WriteLine "  Adding Contact   " & path
                                            iAdGroup.Add path
                                            iAdGroup.SetInfo
                                        End If
                                    End If
                                Else
    'If member is a Distribution list itself, look for it in Active Directory
    'and add it to the Universal Group
                                   DLName = MyDl.GetMember(y).Name
                                   Set conn = CreateObject("ADODB.Connection")
                                    conn.Provider = "ADSDSOObject"
                                   conn.Open "ADs Provider"
                                  ldapStr = "<LDAP://" & DomainContainer _
                                      & ">;(&(&(&(& (mailnickname=*) (| (objectCategory=group) )))(objectCategory=group)(displayName=" & DLName & ")));adspath;subtree"
                                     Set rs = conn.Execute(ldapStr)
                                     If Not rs.EOF Then
                                       Set oUDG = GetObject(rs.Fields(0).Value)
                                        path = oUDG.ADsPath
                                        userFile.WriteLine "  Adding DL   " & path
                                         If Not (iAdGroup.IsMember(path)) Then
                                             iAdGroup.Add path
                                             iAdGroup.SetInfo
                                         End If
                                    End If
                                End If
                Next
            End If
        Next
         Function LoginNameExists (login)
          'Check to see if login name already exists in Active Directory
           LoginNameExists = False 
           Set rootDSE=GetObject(LDAP://RootDSE)
           DomainContainer = rootDSE.Get("defaultNamingContext")
           Set conn = CreateObject("ADODB.Connection")
           conn.Provider = "ADSDSOObject"
           conn.Open "ADs Provider"
           WScript.Echo login
           ldapStr = "<LDAP://" & DomainContainer & _
               ">;(& (sAMAccountName=" & login & ") );adspath;subtree"
           Set rs = conn.Execute(LDAPStr)
           If rs.RecordCount = 1 Then LoginNameExists = True
           conn.Close
    End Function        

    Conclusion

    If the scripts look tricky to you, they are easy to modify to match your Active Directory and e-mail domain. On the other hand, once you learn to master scripting Active Directory and Exchange, the true power of these scripts will reveal itself. The great thing about using a script rather than say a wizard, even a well thought out one like the Outlook Import and Export one is that you get almost absolute flexibility. You can write almost any rule to eliminate unwanted contacts during the migration process. You can decide on whatever naming standard for contacts you choose and make it as complex or as simple as you would like. You can create different contacts in different folders according to any criteria that you choose. The sky is really the limit when it comes to the power of scripting.









    mkm سپاسگزاری کرده است.

  3. #3
    نام حقيقي: 1234

    مدیر بازنشسته
    تاریخ عضویت
    Jul 2009
    محل سکونت
    5678
    نوشته
    5,634
    سپاسگزاری شده
    2513
    سپاسگزاری کرده
    272
    کد:
    http://technet.microsoft.com/en-us/library/bb727091.aspx
    Step-by-Step Guide to Bulk Import and Export to Active Directory


    This guide introduces batch administration of the Active DirectoryTM service, using both the LDAP Data Interchange Format (LDIF) utility and a simple program you can write using the Visual Basic® Scripting Edition (VBScript) development system. Using these tools, you can export, import, and modify objects such as users, contacts, groups, servers, printers, and shared folders.
    On This Page

    Introduction
    Using the LDIFDE Utility
    Using VBScript and ADSI
    Important Notes

    Introduction

    In this guide, you will perform the following tasks:

    • Perform batch operations using the LDIFDE utility. Export users from the Marketing organizational unit (OU) in the Reskit domain into a file format compatible with the LDIF standard format. Perform a batch modification of all the users in the Marketing OU. Use LDIF to create a new user and delete a user.
    • Perform batch operations using ADSI and VBScript. Export users from the Marketing OU in the Reskit domain into a text file, using a script written with ADSI and VBScript. Use VBScript to perform a batch modification of all the users in the Marketing OU. Use VBScript to create a new user and delete a user.

    Requirements and Prerequisites

    You must install the Windows 2000 Server operating system, including Active Directory, on a server in your network. You can then run the Administration Tools from the server or from a workstation running the Windows 2000 Professional operating system.
    This step-by-step guide assumes that you have run the procedures in A Common Infrastructure for Windows 2000 Server Deployment Step-by-Step Part 1.
    The common infrastructure documents specify a particular hardware and software configuration. If you are not using the common infrastructure, you need to make the appropriate changes to this document. For the latest information about hardware requirements and compatibility for servers, clients, and peripherals, see the Windows 2000 Product Compatibility search page (http://www.microsoft.com/windows2000...at/default.asp).
    The Administration Tools are installed by default on all Windows 2000-based domain controllers. The LDIFDE utility described in this guide is installed by default on servers, and can be copied to any Windows 2000-based workstation. The VBScript programs that you create can be run from either servers or workstations.
    For all procedures in this guide, you must be logged on as an administrator. If you log on using an account that does not have administrative privileges, you may not be able to perform export and import operations in Active Directory.
    Top of page

    Using the LDIFDE Utility

    The LDAP Data Interchange Format (LDIF) is an Internet draft standard for a file format that can be used for performing batch operations on directories that conform to the LDAP standards. LDIF can be used to export and import data, allowing batch operations such as Add, Modify, and Delete to be performed in Active Directory. A utility called LDIFDE is included in the Windows 2000 operating system to support batch operations based on the LDIF standard.
    Using LDIF to Export All Objects in the Marketing OU

    You can use LDIFDE to export all objects in the Marketing organizational unit (OU), created in " Step-by-Step Guide to Common Infrastructure Part 1". This example searches the organizational unit for certain objects and creates a file containing the names of those objects.
    To export all objects in the Marketing OU

    1. Click Start, point to Programs, then point to Accessories, and click Command Prompt.
    2. At the command prompt, type:
      ldifde -f marketing.ldf -s hq-res-dc-01-d"ou=Marketing,dc= reskit,dc=com"-psubtree–r"(objectCategory=CN=Person,CN=Schema,C N=Configuration,DC=reskit,DC=com)"

    This creates a LDIF file named Marketing.ldf, by connecting to the server named HQ-RES-DC-01 and executing a subtree search of the Marketing OU for all objects of the category Person. (See Figure 1 below.)
    Note that objectCategory is an indexed attribute designed to enhance search performance.

    Figure 1: Creating an LDF file
    You can use this LDIF file to perform a batch import of all the objects from the Marketing OU into any other LDAP-compatible directory. Some attributes may not be applicable to other implementations of LDAP. In particular, if you use this mechanism to import the objects into another Active Directory, some attributes must be omitted because they are automatically generated during object creation. (If they are not specifically omitted, the operation will fail.)
    For example, the LDIFDE command that is used to omit these attributes is:
    ldifde -f marketing.ldf -s hq-res-dc-01 d
    "ou=Marketing,dc= reskit,dc=com"–r
    >"(objectCategory=CN=Person,CN=Schema,CN=Configura tion,DC=reskit,DC=com)" –m
    Using LDIF to Modify All Objects in the Marketing OU

    In this example, the entire Marketing organization has moved to a new office address. You use LDIF to perform a batch modification for all user objects in the Marketing organization by altering the state, street, locality, and postal code attributes.
    To modify all objects in the Marketing OU

    1. Click Start, point to Programs, then point to Accessories, and click Command Prompt.
    2. At the command prompt, type the following command to extract the required entries:
      ldifde -f marketing.ldf -s hq-res-dc-01-d"ou=Marketing,dc= reskit,dc=com"-psubtree–r"(objectCategory=CN=Person,CN=Schema,C N=Configuration,DC=reskit,DC=com)" –l "l,st,streetAddress, postalCode"
    3. Use a text editor such as Notepad to edit the LDIF file, Marketing.ldf. (Save the file as an .ldf file.) Modify each entry so that it is similar to that shown in Figure 2 below.

      Figure 2: Editing attributes for a move
    4. Run LDIFDE to import the modifications into Active Directory. At the command prompt, type the following command, and then press > Enter. (See Figure 3 below.)
      ldifde –i -f marketing.ldf -s hq-res-dc-01

      Figure 3: Importing modifications into the Active Directory
    5. To confirm that the entries have been modified, check the Active Directory Users and Computers snap-in. (For help with using this snap-in, see the Step-by-Step Guide to Managing the Active Directory. )

    For further information on using LDIFDE, type LDIFDE /? at the command prompt.
    Note: Another utility called CSVDE performs the same export functions as LDIFDE, but uses a comma-separated file format. Import operations with CSVDE are "add" only, and CSVDE does not offer the ability to modify or delete objects. The CSV file format is supported by applications such as Microsoft Excel.
    Using LDIF to Create a New User

    In this example, you use LDIF to add a new user named James Smith to the Marketing organizational unit.

    1. Start a text editor, such as Notepad, and create a new text file named Newuser.ldf. (Save the file as an ldif file, not as a text file.)
    2. Edit the LDIF file Newuser.ldf, and add the following text (see Figure 4 below):
      dn: CN=JamesSmith,OU=Marketing,DC=reskit,DC=com
      changetype: add
      cn: James Smith
      objectClass: user
      samAccountName: James
      > givenName: James
      > sn: Smith
    3. Save and close the LDIF file.
    4. Run LDIFDE to import the new user into Active Directory. On the Start menu, point to Programs, then point to Accessories, and click Command Prompt. Type the following command, and then press Enter.
      ldifde –i -f newuser.ldf -s hq-res-dc-01
    5. To confirm that the new user has been created, check the Active Directory Users and Computers snap-in.

      Figure 4: Adding a new user to the Marketing OU

    Using LDIF to Delete a User

    In this example, you use LDIF to remove the user named James Smith from the Marketing OU.

    1. Start a text editor such as Notepad, and create a new file named Deluser.ldf.
    2. Edit the LDIF file Deluser.ldf, and add the following text.
      dn: CN=JamesSmith,OU=Marketing,DC=reskit,DC=com
      changetype: delete

      Figure 5: Remove James Smith from OU
    3. Run LDIFDE to delete the user from Active Directory. At the command prompt, type the following command, and then press Enter.
      ldifde –i -f deluser.ldf -s hq-res-dc-01
    4. To confirm that the user has been deleted, check the Active Directory Users and Computers snap-in.

    Top of page

    Using VBScript and ADSI

    Active Directory Services Interfaces (ADSI) makes it easy to develop directory-enabled applications. In conjunction with the Windows Script Host, batch directory operations can be scripted using VBScript or Jscript® development software. In this guide, the procedures that were described in the previous section (which used LDIF) are performed using simple applications written in VBScript.
    Please note that these scripts do not include any error checking, nor are they meant to provide a programmer's reference to VBScript and ADSI. All of the examples included here assume you are logged on with the proper credentials on a machine that is a member of the target domain. It is possible in ADSI to explicitly specify credentials and a target domain. For more information on this, see the documentation on ADSI's OpenDSObject in the Platform SDK (http://msdn.microsoft.com/downloads/...m/platform.asp).
    After each procedure, confirm that the entries have been modified by checking the Active Directory Users and Computers snap-in.
    Using VBScript to Export All Objects in the Marketing OU

    In this example, you use a text editor such as Notepad to create a VBScript program. The script searches the Marketing OU and creates a text file that lists all of the user objects and a subset of their attributes.
    To create the export script
    Copy the following text into your text editor:
    کد:
     
    'Global variables
     Dim oContainer
     Dim OutPutFile
     Dim FileSystem
     'Initialize global variables
     Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
     Set OutPutFile = FileSystem.CreateTextFile("marketing.txt", True)
     SetoContainer=GetObject("LDAP://OU=marketing,DC=reskit,DC=com")
     'Enumerate Container
     EnumerateUsers oContainer
     'Clean up
     OutPutFile.Close
     Set FileSystem = Nothing
     Set oContainer = Nothing
     WScript.Echo "Finished"
     WScript.Quit(0)
     Sub EnumerateUsers(oCont)
     Dim oUser
     For Each oUser In oCont
     Select Case LCase(oUser.Class)
     Case "user"
     If Not IsEmpty(oUser.distinguishedName) Then
     OutPutFile.WriteLine "dn: " & oUser.distinguishedName
     End If 
     If Not IsEmpty(oUser.name) Then 
     OutPutFile.WriteLine "name: " & oUser.Get ("name")
     End If
     'need to do this because oUser.name would get back the Relative 
     Distinguished name (i.e. CN=Jo Brown)
     If Not IsEmpty(oUser.st) Then 
     OutPutFile.WriteLine "st: " & oUser.st
     End If
     If Not IsEmpty(oUser.streetAddress) Then 
     OutPutFile.WriteLine "streetAddress: " & oUser.streetAddress
     End If
     Case "organizationalunit" , "container"
     EnumerateUsers oUser
     End Select
     OutPutFile.WriteLine 
     Next
     End Sub


    1. Save the file as Export.vbs.
    2. At the command prompt type export.vbs and press Enter. This creates a file named Marketing.txt, which contains a list of users and some of their attributes, such as distinguished name, name, state, and street address.

    With appropriate modification, this script can be used with any application that supports COM and Visual Basic technologies. Such applications include Microsoft Visual Basic, Microsoft Excel, and Microsoft Access. Scripting can also be hosted by Internet Explorer and Internet Information Services 5.0, which is part of Windows 2000 Server.
    Using VBScript to Modify All Objects in the Marketing OU

    In this example, the Marketing organization has moved to a new office address. A simple VBScript program is used to perform a batch modification for all user objects in the Marketing organization. The script alters the state, street, locality, and postal code attributes.

    1. Copy the following text into your text editor:
      کد:
      Dim
       oContainer Set  oContainer=GetObject("LDAP://
       OU=marketing,DC=reskit,DC=com")
       ModifyUsers oContainer
       'cleanup
       Set oContainer = Nothing
       WScript.Echo "Finished"
       Sub ModifyUsers(oObject)
       Dim oUser
      oObject.Filter = Array("user")
      For Each oUser in oObject
      oUser.Put "st","New York"
      oUser.Put "streetAddress","825 Eighth Avenue"
      oUser.Put "postalCode","10019"
      oUser.Put "l","New York"
      oUser.SetInfo
      Next
       End Sub
    2. Save the file as Modify.vbs.
    3. At the command prompt, type modify.vbs and press Enter. This processes all objects in the Marketing organizational unit and modifies all users, altering the state, street address, postal code, and locality attributes.

    Using VBScript to Create a User Object in the Marketing OU

    In this example, you use VBScript to add a new user to the Marketing organization. This example illustrates how easy it is to use ADSI and VBScript to programmatically access the directory. Note that in this example, only a limited set of attributes are configured during the user creation.
    To create the script and add the user

    1. Copy the following text into your text editor:

    کد:
    Dim oContainer 'Parent container
     of new   user Dim
     oUser 'Created user
     'Get parentcontainerSetoContainer=GetObject("LDAP://OU=marketing,
     DC=reskit,DC=com")
     'Create user
     Set oUser = oContainer.Create("User","CN=Jo Brown")
     'Assign properties values to user
     oUser.Put "samAccountName","Jo"
     oUser.Put "givenName","Jo"
     oUser.Put "sn","Brown"
     oUser.Put "userPrincipalName","jo@reskit.com"
     oUser.SetInfo
     'Clean up
     Set oUser = Nothing
     Set oContainer = Nothing
     WScript.Echo "Finished"


    1. Save the file as Adduser.vbs.
    2. At the command prompt, type adduser.vbs and press Enter. This creates a new user named Jo Brown in the Marketing OU.

    Using VBScript to Delete a User

    In this example, you use VBScript to delete a user from the Marketing organization.

    1. Copy the following text into your text editor:

    کد:
    Dim oContainer 'Parent container of object to be
     deleted 'Get parent
     container Set  oContainer=GetObject("LDAP://OU=marketing,
     DC=reskit,DC=com")
     'Delete user
     oContainer.Delete "user","CN=Jo Brown"
     'Clean up
     Set oContainer = Nothing
     WScript.Echo "Finished"


    1. Save the file as Deluser.vbs.
    2. At the command prompt, type deluser.vbs and press Enter. This deletes the user Jo Brown from the Marketing OU.


    Important Notes

    The example company, organization, products, people, and events depicted in these step-by-step guides are fictitious. No association with any real company, organization, product, person, or event is intended or should be inferred.
    This common infrastructure is designed for use on a private network. The fictitious company name and DNS name used in the common infrastructure are not registered for use on the Internet. Please do not use this name on a public network or Internet.
    The Active Directory service structure for this common infrastructure is designed to show how Windows 2000 features work and function with the Active Directory. It was not designed as a model for configuring an Active Directory for any organization–for such information see the Active Directory documentation.



    mkm سپاسگزاری کرده است.

  4. #4
    نام حقيقي: 1234

    مدیر بازنشسته
    تاریخ عضویت
    Jul 2009
    محل سکونت
    5678
    نوشته
    5,634
    سپاسگزاری شده
    2513
    سپاسگزاری کرده
    272
    کد:
    http://www.computerperformance.co.uk/vbscript/vbscript_contact_create.htm
    Example 1 - Script to Create a Contact in Active Directory

    Prerequisites

    Recommended: You logon as administrator, preferably at a domain controller. Remote Desktop would be a suitable alternative. If that is not possible, you could get these sample scripts to work from an XP machine as a non-administrator, but why introduce extra complications? At the beginning you want easy success, with fewest obstacles.
    Instructions for Creating a Contact in Active Directory

    1. You need access to a Windows Active Directory domain.
    2. Copy and paste the example script below into notepad or a VBScript editor.
    3. Decide what value to use for strContainer. Where is your spreadsheet?
    4. Change the values of the variable strEmail to a Contact that you know.
    5. Save the file with a .vbs extension, for example: contact.vbs
    6. Double click contact.vbs. Open Active Directory Users and Computers and check the strContainer container for strContactName. If necessary, 'Refresh' the contents of your OU.

    Script to Create a Contact in your Active Directory

    کد:
    ' Contact .vbs
    ' Purpose VBScript to create a contact object in Active Directory
    ' Author Guy Thomas http://computerperformance.co.uk/
    ' Version  1.3 - May 2005
    ' --------------------------------------------------------------' 
    Option Explicit
    Dim objRoot, objOU, objDomain, objContact, strYourDescription
    Dim strDNS, strContainer,  strContactName, strEmail
    
    ' Set string variables
    strContainer = "OU=Suppliers"
    strContactName = "cn=MySupplier1"
    strEmail = "supplier@supplyme.com"
    strYourDescription = "Guy's Contact"
    
    '  Section to attach to Active Directory
    Set objRoot = GetObject("LDAP://rootDSE")
    strDNS = objRoot.Get("defaultNamingContext") 
    Set objDomain = GetObject("LDAP://" & strDNS) 
    
    ' Section to create the contact
    Set objOU = GetObject("LDAP://"& strContainer & "," & strDNS)
    Set objContact = objOU.Create("contact", strContactName)
    objContact.Put "Description", strYourDescription
    objContact.Put  "Mail", strEmail
    objContact.SetInfo
    
    Wscript.Echo "Look in " & strContainer & " for (F5) " & strEmail
    
    ' End of Sample  Contact VBScript



    mkm سپاسگزاری کرده است.

  5. #5
    نام حقيقي: 1234

    مدیر بازنشسته
    تاریخ عضویت
    Jul 2009
    محل سکونت
    5678
    نوشته
    5,634
    سپاسگزاری شده
    2513
    سپاسگزاری کرده
    272
    البته چون سوال شما مقداری گنگ است ، پیش خودم فکر کردم شاید منظورتان این کار است

    کد:
    http://support.microsoft.com/?scid=kb%3Ben-us%3B238007&x=8&y=6
    How to Configure the Address Book to Query Users Contained in Active Directory


    The Address Book is the default search client that ships with Windows 2000 and Microsoft Internet Explorer 5. It is a high-level Lightweight Directory Access Protocol (LDAP) client, and LDAP does not support users specifying filters for a search. Instead, you can input the string for the filter and the Ambiguous Name Resolution (ANR) set is used

    Windows 2000 Considerations

    When you install Windows 2000, the Address Book is configured to search a particular Active Directory server. You are not required to specify a Base Distinguished Name (BaseDN) or a server name. Setup configures the BaseDN and server name, and they are displayed as null.

    To view Active Directory properties:
    1. Click Start, point to Programs, point to Accessories, and then click Address Book.
    2. On the Tools menu, click Accounts.
    3. When the Internet Accounts dialog box is displayed, you can add, remove, or modify an existing account by selecting the appropriate account, and then clicking Properties.

    NOTE: The Server name and Account name fields are displayed as null. The Locator service caches the actual server and account name. When you log on to a workstation, the Locator service attempts to find a domain controller. The name of the domain controller detected by the Locator service is used as the server name, and the account that you use to log on serves as the account name. Back to the top
    Downlevel Client Considerations with the Address Book

    Internet Explorer 5 is considered a downlevel client when it is installed on a computer running Microsoft Windows 98 or Microsoft Windows NT 4.0. To use the Address Book to search Active Directory, you must configure the following items:
    • Server name
    • BaseDN
    • Account name (if not validating against Active Directory)

    To configure the Address Book with downlevel clients:
    1. Install Internet Explorer 5 (if it is not currently installed).
    2. Click Start, point to Programs, point to Accessories, and then click Address Book.
    3. On the Tools menu, click Accounts.
    4. To add a new account, click Add. This starts the Internet Connection wizard.
    5. In the Internet directory (LDAP) server box, type the name of an LDAP server (Windows 2000 domain controller). You can also type the domain name, but do not use the fully qualified domain name (FQDN) in either case.
    6. Click Next, click Next, and then click Finish.
    7. The account you just created is not displayed in the list. Click to select the account, and then click Properties.
    8. Click to select the This server requires me to log on check box.
    9. In the Account name box, type Domainname\Username, where Domainname is the name of your domain and Username is the user's name. In the Password box, type the appropriate password.
    10. On the Advanced tab, the value displayed in the Directory service (LDAP) box is 3268 by default (the global catalog port). If you clear the Directory service (LDAP) box and click Use Default, the value changes to 389. If you use 389, you need to type data the Search Base box (it should read DC=domainname,DC=com).

      NOTE: Port 3268 is recommended for most searches. Also, if you select the This server requires a secure connection (SSL) check box on the Advanced tab, the port number is changed to 636. If you are using port 636 to search, ensure that the Search base box is populated with the correct base DN (that is, DC=domainname,DC=com).
    11. Click OK to save the changes.

    To search for a user in Active Directory:
    1. Click Start, point to Programs, point to Accessories, and then click Address Book.
    2. Click Find People.
    3. In the Look In box, click Active Directory (for Windows 2000 clients) or the name you chose in step 5 above.
    4. Type a user's name or e-mail address, and then click Find Now.
    5. When the user account is displayed, you can view the user's properties or add the user to the Address Book.

    For additional information, click the article number below to view the article in the Microsoft Knowledge Base: 254610 (System Event ID 36876 When Using LDAP SSL Query of the Active Directory ) System Event ID 36876 When Using LDAP SSL Query of the Active Directory




    mkm سپاسگزاری کرده است.

کلمات کلیدی در جستجوها:

ldifde directoryservices objcontact

ldifde what happens import object already exists

global

Email2Address outlook contact gives smtp

1

vbs

SetoContainer=GetObject(LDAP://OU=marketing DC=reskit DC=com)

vbs dnexist

برچسب برای این موضوع

مجوز های ارسال و ویرایش

  • شما نمی توانید موضوع جدید ارسال کنید
  • شما نمی توانید به پست ها پاسخ دهید
  • شما نمی توانید فایل پیوست ضمیمه کنید
  • شما نمی توانید پست های خود را ویرایش کنید
  •