Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Extract Data From Active Directory

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Extract Data From Active Directory

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel and Active Directory javagirl Excel Discussion (Misc queries) 2 March 30th 07 05:04 PM
Data Connection - Active Directory Rob Excel Discussion (Misc queries) 1 August 11th 06 06:56 PM
active directory? Tim[_39_] Excel Programming 0 August 15th 04 08:34 AM
Active Directory Ulf Nilsson Excel Programming 2 April 27th 04 07:08 AM


All times are GMT +1. The time now is 03:02 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"