Chapter 11: LDAP Infrastructure Management Code

   

Chapter 11: LDAP Infrastructure Management Code

Discovering the Architecture of an Existing LDAP Directory Using a VBScript Active Server Page

 Dim Container Dim Entry Dim StartingPoint 'StartingPoint = "/ou=People" Set Container = GetObject("LDAP://LDAP_SERVER/o=airius.com" & StartingPoint) For Each Entry In Container      Response.Write "Entry Name: " & Entry.Name & "Class: " & Entry.Class & "<BR>" Next 

Querying Entry Attributes with ADSI Using Anonymous Access in a VBScript Active Server Page

 On Error Resume Next Dim Container Dim User Set Container = GetObject("LDAP://LDAP_SERVER/o=airius.com/ou=People") For Each User In Container      Response.Write "UserID: " & User.Get("uid") & "Common Name: " & User.Get("cn") & graphics/ccc.gif "Surname:  " & User.Get("sn") & "<BR>" Next 

Querying Entry Attributes with ADSI Using Alternate Credentials in a VBScript Active Server Page

 On Error Resume Next Dim dso Dim Container Dim User Set dso = GetObject("LDAP:") Set Container = dso.OpenDSObject("LDAP://LDAP_SERVER/o=airius.com/ou=People", "cn=Directory Manager", "l@undrym@t1974", 0) For Each User In Container      Response.Write "UserID: " & User.Get("uid") & "Common Name: " & User.Get("cn") & graphics/ccc.gif "Surname: " & User.Get("sn") & "<BR>" Next 

Modifying Entry Attributes Using ADSI Using a VBScript Active Server Page

 Dim dso Dim Container Dim User Set dso = GetObject("LDAP:") Set Container = dso.OpenDSObject("LDAP://LDAP_SERVER/o=airius.com/ou=People", graphics/ccc.gif "cn=Directory Manager", "l@undrym@t1974", 0) Set User = Container.GetObject("inetorgperson", "uid=aknutson") User.Put "sn", "McNally" User.SetInfo 

Creating a New Entry Using ADSI In a VBScript Active Server Page

 Dim dso Dim Container Dim User Set dso = GetObject("LDAP:") Set Container = dso.OpenDSObject("LDAP://LDAP_SERVER/o=airius.com/ou=People", graphics/ccc.gif "cn=Directory Manager", "l@undrym@t1974", 0) Set User = Container.Create("inetorgperson", "uid=teck") User.Put "cn", "Thomas Eck" User.Put "sn", "Eck" User.SetInfo 

Removing an Entry Using ADSI In a VBScript Active Server Page

 Dim dso Dim Container Set dso = GetObject("LDAP:") Set Container = dso.OpenDSObject("LDAP://LDAP_SERVER/o=airius.com/ou=People", graphics/ccc.gif "cn=Directory Manager", "l@undrym@t1974", 0) Call Container.Delete("inetorgperson", "uid=teck") 

Using ADO to Search an LDAP Directory Using a VBScript Active Server Page

 Dim Connection Dim RS Dim Entry Dim Index Index = 0 Set Connection = New ADODB.Connection Connection.Provider = "ADsDSOObject" Connection.Open "ADSI" Set RS = Connection.Execute("SELECT cn,telephonenumber FROM 'LDAP://LDAP_SERVER/ graphics/ccc.gif o=airius.com/ou=people' WHERE sn='carter'") While Not RS.EOF     For i = 0 To RS.Fields.Count - 1         If RS.Fields(i).Type = adVariant And Not (IsNull(RS.Fields(i).Value)) Then             For j = LBound(RS.Fields(i).Value) To UBound(RS.Fields(i).Value)                Entry = Entry & RS.Fields(i).Value(j) & vbTab             Next j         Else              Entry = Entry & RS.Fields(i).Value & vbTab         End If         If Index = RS.Fields.Count - 1 Then             Response.Write Entry & "<BR>"         End If         Index = Index + 1     Next i     Entry = ""     Index = 0     RS.MoveNext Wend 

Creating a New Exchange Mailbox Using a VBScript Active Server Page

 Dim ExchangeServerName Dim ExchangeServerOrganization Dim ExchangeServerSite Dim Mailbox Dim MailboxParentContainer Dim MailboxRelativePath Dim MailboxDisplayName Dim MailboxFirstName Dim MailboxLastName Dim MailboxMiddleInitial Dim MailboxAlias Dim MTA Dim MDB Dim MailboxSMTPAddress Dim MailboxX400Address Dim MailboxCCMailAddress Dim MailboxMSMailAddress Dim NTUserAccountToAssociate Dim UserDomain Dim SID Dim Security Dim SecurityDescriptor Dim DiscretionaryACL Dim AccessControlEntry ExchangeServerName = "EXCHANGE_SERVER" ExchangeServerOrganization = "ADSITest" ExchangeServerSite = "Macmillan" MailboxRelativePath = "" MailboxDisplayName = "Eck, Thomas E." MailboxFirstName = "Thomas" MailboxLastName = "Eck" MailboxMiddleInitial = "E" MailboxAlias = "Thomas.Eck" UserDomain = "UserDomain" NTUserAccountToAssociate = "teck" MTA = "cn=Microsoft MTA,cn=" & ExchangeServerName & ",cn=Servers,cn=Configuration,ou=" & ExchangeServerSite & ",o=" & graphics/ccc.gif ExchangeServerOrganization MDB = "cn=Microsoft Private MDB,cn=" & ExchangeServerName & ",cn=Servers,cn=Configuration, graphics/ccc.gif ou=" & ExchangeServerSite & ",o=" & ;ExchangeServerOrganization MailboxSMTPAddress = MailboxAlias & "@" & ExchangeServerSite & "." & graphics/ccc.gif ExchangeServerOrganization & ".com" MailboxX400Address = "c=US;a= ;p=" & ExchangeServerOrganization & ";o=" & graphics/ccc.gif ExchangeServerSite & ";s=" & MailboxLastName & ";g=" & MailboxFirstName & ";i=" & graphics/ccc.gif MailboxMiddleInitial MailboxCCMailAddress = MailboxLastName & ", " & MailboxFirstName & " at " & graphics/ccc.gif ExchangeServerSite MailboxMSMailAddress = UCase(ExchangeServerOrganization &"/" & ExchangeServerSite & "/" graphics/ccc.gif &MailboxAlias) Set MailboxParentContainer = GetObject("LDAP://" & ExchangeServerName & "/o=" & graphics/ccc.gif ExchangeServerOrganization & "/ou=" & ExchangeServerSite & "/cn=Recipients" & graphics/ccc.gif MailboxRelativePath) Set Mailbox = MailboxParentContainer.Create("organizationalPerson", "cn=" & MailboxAlias) Mailbox.Put "mailPreferenceOption", 0 Mailbox.Put "givenName", MailboxFirstName Mailbox.Put "sn", MailboxLastName Mailbox.Put "cn", MailboxDisplayName Mailbox.Put "uid", MailboxAlias Mailbox.Put "Home-MTA", MTA Mailbox.Put "Home-MDB", MDB Mailbox.Put "mail", MailboxSMTPAddress Mailbox.Put "MAPI-Recipient", True Mailbox.Put "rfc822Mailbox", MailboxSMTPAddress Mailbox.Put "textEncodedORAddress", MailboxX400Address Mailbox.PutEx ADS_PROPERTY_APPEND, "otherMailbox", Array("CCMAIL$" & MailboxCCMailAddress, graphics/ccc.gif "MS$" & MailboxMSMailAddress) SID.SetAs ADS_SID_WINNT_PATH, "WinNT://" & UserDomain & "/" & NTUserAccountToAssociate & graphics/ccc.gif ",user" sidHex = SID.GetAs(ADS_SID_HEXSTRING) Mailbox.Put "Assoc-NT-Account", sidHex Mailbox.SetInfo Set SecurityDescriptor = Security.GetSecurityDescriptor(Mailbox.ADsPath) Set DiscretionaryACL = SecurityDescriptor.DiscretionaryACL AccessControlEntry.AceType = ADS_ACETYPE_ACCESS_ALLOWED AccessControlEntry.Trustee = UserDomain & "\" & MailboxAlias AccessControlEntry.AccessMask = ADS_RIGHT_EXCH_MAIL_SEND_AS Or graphics/ccc.gif ADS_RIGHT_EXCH_MAIL_RECEIVE_AS Or ADS_RIGHT_EXCH_MODIFY_USER_ATT DiscretionaryACL.AddAce AccessControlEntry SecurityDescriptor.DiscretionaryACL = DiscretionaryACL Security.SetSecurityDescriptor SecurityDescriptor 

Removing an Existing Exchange Mailbox Using a VBScript Active Server Page

 Dim ExchangeServerName Dim ExchangeServerOrganization Dim ExchangeServerSite Dim MailboxParentContainer Dim MailboxRelativePath Dim MailboxToRemove ExchangeServerName = "EXCHANGE_SERVER" ExchangeServerOrganization = "ADSITest" ExchangeServerSite = "Macmillan" MailboxRelativePath = "" MailboxToRemove = "Thomas.Eck" Set MailboxParentContainer = GetObject("LDAP://" & ExchangeServerName & "/o=" & graphics/ccc.gif ExchangeServerOrganization & "/ou=" & ExchangeServerSite & "/cn=Recipients" & graphics/ccc.gif MailboxRelativePath) Call MailboxParentContainer.Delete("organizationalPerson", "cn=" & MailboxToRemove) 

Adding a Distribution List Member Using a VBScript Active Server Page

 Dim ExchangeServerName Dim ExchangeServerOrganization Dim ExchangeServerSite Dim DistributionList Dim DistributionListName Dim DistributionListRelativePath Dim DLMemberMailboxName ExchangeServerName = "EXCHANGE_SERVER" ExchangeServerOrganization = "ADSITest" ExchangeServerSite = "Macmillan" DistributionListRelativePath = "" DistributionListName = "DL_Research_Development" DLMemberMailboxName = "Thomas.Eck" Set DistributionList = GetObject("LDAP://" & ExchangeServerName & "/o=" & graphics/ccc.gif ExchangeServerOrganization & "/ou=" & ExchangeServerSite & "/cn=Recipients" & graphics/ccc.gif DistributionListRelativePath & "/cn=" & DistributionListName) DistributionList.Add ("LDAP://" & ExchangeServerName & "/o=" & ExchangeServerOrganization graphics/ccc.gif & "/ou=" & ExchangeServerSite & "/cn=Recipients" & "/cn=" & DLMemberMailboxName) DistributionList.SetInfo 

Removing a Distribution List Member Using a VBScript Active Server Page

 Dim ExchangeServerName Dim ExchangeServerOrganization Dim ExchangeServerSite Dim DistributionList Dim DistributionListName Dim DistributionListRelativePath Dim DLMemberMailboxName ExchangeServerName = "EXCHANGE_SERVER" ExchangeServerOrganization = "ADSITest" ExchangeServerSite = "Macmillan" DistributionListRelativePath = "" DistributionListName = "DL_Engineering" DLMemberMailboxName = "Thomas.Eck" Set DistributionList = GetObject("LDAP://" & ExchangeServerName & "/o=" & graphics/ccc.gif ExchangeServerOrganization & "/ou=" & ExchangeServerSite & "/cn=Recipients" & graphics/ccc.gif DistributionListRelativePath & "/cn=" & DistributionListName) DistributionList.Remove ("LDAP://" & ExchangeServerName & "/o=" & graphics/ccc.gif ExchangeServerOrganization & "/ou=" & ExchangeServerSite & "/cn=Recipients" & "/cn=" & graphics/ccc.gif DLMemberMailboxName) DistributionList.SetInfo 

Determining the Distribution List Owner Using a VBScript Active Server Page

 Dim ExchangeServerName Dim ExchangeServerOrganization Dim ExchangeServerSite Dim DistributionList Dim DistributionListName Dim DistributionListRelativePath ExchangeServerName = "EXCHANGE_SERVER" ExchangeServerOrganization = "ADSITest" ExchangeServerSite = "Macmillan" DistributionListRelativePath = "" DistributionListName = "DL_Senior_Management" Set DistributionList = GetObject("LDAP://" & ExchangeServerName & "/o=" & graphics/ccc.gif ExchangeServerOrganization & "/ou=" & ExchangeServerSite & "/cn=Recipients" & graphics/ccc.gif DistributionListRelativePath &"/cn=" & DistributionListName) Response.Write DistributionList.Owner 

   
Top


Windows NT. 2000 ADSI Scripting for System Administration
Windows NT/2000 ADSI Scripting for System Administration
ISBN: 1578702194
EAN: 2147483647
Year: 2000
Pages: 194
Authors: Thomas Eck

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net