Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
I have a pretty fair idea how to write VBS scripts . I am trying to put most of my scripts into a excel shreadsheet , so I can run them by the click of a button and they can be displayed as needed. So For example if I want to list all the domain controllers in a region, I select the region click a button and then it populates a worksheet Is this possible ? If so where can I find some docs on how to go about doing this ? Thanks |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Adrian,
Are you asking how to enumerate the domain controllers, or how to take the info you get back and put it into Excel? If the former: http://groups.google.com/group/micro...c346e0678dce46 Instead of writing the results to the screen, you would iterate through the cells of a worksheet and write them there. Here's a quick-and-dirty example of how you could do that: Sub EnumerateDCs() Dim l As Long Dim oRootDSE As Object Dim strConfigNC As String Dim oConnection As Object Dim oCmd As Object Dim strQuery As String Dim oRecordset As Object Dim oParent As Object ' Get the Configuration Naming Context Set oRootDSE = GetObject("LDAP://RootDSE") strConfigNC = oRootDSE.Get("configurationNamingContext") ' Set up the oConnectionection Set oConnection = CreateObject("ADODB.Connection") oConnection.Provider = "ADsDSOObject" oConnection.Open "ADs Provider" ' Build the query to find all Exchange ServeoRecordset strQuery = "<LDAP://" & strConfigNC & ";" & _ "(objectClass=nTDSDSA);ADsPath;subtree" Set oCmd = CreateObject("ADODB.Command") oCmd.ActiveConnection = oConnection oCmd.CommandText = strQuery Set oRecordset = oCmd.Execute ' Iterate through the results If oRecordset.EOF And oRecordset.Bof Then MsgBox "No domain controllers found." Else While Not oRecordset.EOF l = l + 1 Set oParent = GetObject(GetObject(oRecordset.Fields( _ "ADsPath")).Parent) ' Output the name of the server Cells(l, 1).Value = oParent.cn Cells(l, 2).Value = oParent.dNSHostName oRecordset.MoveNext Wend End If End Sub To call this from a button, make sure the Visual Basic toolbar is visible, then click the Control Toolbox. Add an ActiveX CommandButton to the worksheet, then right-click and modify properties as needed (make sure you set TakeFocusOnClick to False). Double-click the button, and you'll be taken to the click event - that's where you'd call EnumerateDCs: Private Sub cmdListDCs_Click() EnumerateDCs End Sub -- Regards, Jake Marx www.longhead.com [please keep replies in the newsgroup - email address unmonitored] Adrian wrote: Hi I have a pretty fair idea how to write VBS scripts . I am trying to put most of my scripts into a excel shreadsheet , so I can run them by the click of a button and they can be displayed as needed. So For example if I want to list all the domain controllers in a region, I select the region click a button and then it populates a worksheet Is this possible ? If so where can I find some docs on how to go about doing this ? Thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel and Active Directory | Excel Discussion (Misc queries) | |||
Data Connection - Active Directory | Excel Discussion (Misc queries) | |||
active directory? | Excel Programming | |||
Active Directory | Excel Programming |