Jump to content

Recommended Posts

Posted

I'm trying to implement the Active Directory integration script that is on the Lanview community forums and I have a slight problem.

 

The script runs with no problem and successfuly queries my AD, however the structure written back to Lanview isn't quite as I need it to be, due to the way my AD is organised.

 

Currently the OUs I'm getting created in Lanview by the script are:

Domain Controllers

Member Servers

Network Computers

Network Tool Stations

Staff

Students

 

These are all top level OUs, and all have sub-containers. It is specifically the Sub-OUs of 'Network Computers' that I really want to appear and be populated in LanView and the others can all be ignored by the script.

 

Is this possible?

 

Here is the script that is called at program startup (I'm sure that the AD scripting can be tweaked by some knowledgable soul on here):

'=========================================================================
' AUTHOR: Jose Mosquera 
' DATE: 16/12/2006
'
' PURPOSE: Connect to AD Root, enumerate each OU to enumerate all computers
' in each OU, read the host name, then
' generate a report text file with all the OU's and computers and
' their properties.
'
' COMMENT: 
'=========================================================================
Option Explicit
Dim objRootDSE
Dim objDomain
Dim objContainer
Dim objOU
Dim objComputers
Dim objShell
Dim objReportFile
ReDim arrComputers(100,1)
ReDim arrOUs(100,1)
Dim strPrompt
Dim strCurDir
Dim intRetVal
Dim intCount
Dim intX
Dim intY
Dim strDummy
Dim GroupsFile

strDummy = """" & "~Dummy" & """"
GroupsFile = "Groups.bind"

' Connect to AD Root.
Set objRootDSE = GetObject("LDAP://RootDSE")
' Get domain name.
Set objDomain = GetObject("LDAP://" & objRootDSE.Get("DefaultNamingContext"))
' Call Sub that will list each OU.
Call EnumOUs(objDomain.ADsPath)

CreateGroupsFile ' Create text file to host found data.
DisplayADObjects ' Call notepad and display text file to user.

'--------------------------------------------------------------------------------------------------
' ====================================================================================
' TITLE: EnumOUs
'
' PURPOSE: Loop through all OU container from Active Directory Root 
' and pass current found OU to EnumComputers
'
' HOW TO USE: Call EnumOUs(objOU.ADsPath)
'
' ====================================================================================
Sub EnumOUs(sADsPath)
' Connect to Active Directory First Container.
Set objContainer = GetObject(sADsPath)
' Filter to only Organizational Unit.
objContainer.Filter = Array("OrganizationalUnit")
intX=0
intY=0
For Each objOU in objContainer
If objOU.Name <> "OU=Printers" AND objOU.Name <> "OU=MyBusiness" then
      arrOUs(intX,0) = strDummy
      arrOUs(intX,1) = """" & Mid(objOU.Name, 4) & """"
      EnumComputers(objOU.ADsPath) ' If there are Computers in this OU, will extract them.
      intX = intX + 1
End If
Next

End Sub
'--------------------------------------------------------------------------------------------------
' ====================================================================================
' TITLE: EnumComputers
'
' PURPOSE: Loop through all user container in each OU and create an 
' array with some properties for each computer.
'
' HOW TO USE: Call EnumComputers(objOU.ADsPath)
'
' ====================================================================================
Sub EnumComputers(sADsPath)
' sADsPath contain current OU from EnumOUs. Connect to it.
Set objContainer = GetObject(sADsPath)
' Filter only computer objects
objContainer.Filter = Array("Computer")
' Extract Computer Name only
For Each objComputers in objContainer
arrComputers(intY,0) = """" & Mid(objComputers.Name, 4) & """"
arrComputers(intY,1) = arrOUs(intX,1)
'Msgbox arrComputers(intY,0) & " " & arrComputers(intY,1)
intY = intY + 1
Next

End Sub
'--------------------------------------------------------------------------------------------------
' ====================================================================================
' TITLE: CreateGroupsFile
'
' PURPOSE: Create a Groups.bind file hosting data from Active Directory Computers
' in any OUs
'
' HOW TO USE: Call CreateGroupsFile
'
' ====================================================================================
Sub CreateGroupsFile
Dim objFSO
Dim strReportFile

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Get directory from where this script is executed.

strReportFile = "C:\Program Files\LanView3 Server\Bindaries\" + GroupsFile

Set objReportFile = objFSO.CreateTextFile(strReportFile, True)
End Sub
'--------------------------------------------------------------------------------------------------
' ====================================================================================
' TITLE: DisplayADObjects
'
' PURPOSE: Write report of all computers found in Active Directory.
'
' HOW TO USE: Call DisplayADObjects
'
' ====================================================================================
Sub DisplayADObjects

' Add Default groups as seen in standard LANVIWEW SERVER.
objReportFile.WriteLine (strDummy & ","  & """" & "IAM Disabled" & """") 
objReportFile.WriteLine (strDummy & ","  & """" & "IAM Ignored" & """") 
objReportFile.WriteLine (strDummy & ","  & """" & "IAM Managers" & """") 
objReportFile.WriteLine (strDummy & ","  & """" & "Watched Object" & """") 
objReportFile.WriteLine (strDummy & ","  & """" & "Known PC's" & """") 

'Output the OU's Name
For intCount = 0 To UBound(arrOUs)
If Not IsNoData(arrOUs(intCount,0)) Then
objReportFile.WriteLine(arrOUs(intCount,0) & "," & arrOUs(intCount,1))
End If
Next


' Add each computer found in AD.
For intCount = 0 To UBound(arrComputers)
'Verify each value in arrComputers. Write only if there is data.
If Not IsNoData(arrComputers(intCount,0)) Then
objReportFile.WriteLine(arrComputers(intCount,0) & "," & arrComputers(intCount,1))
End If
Next

objReportFile.Close
End Sub
' ====================================================================================
' TITLE: IsNoData
'
' PURPOSE: Verify if passed parameter variable contain something.
'
' RETURN: True if contain something, otherwise, False.
'
' HOW TO USE: intResult = IsNoData(varSource) or
' If IsNoData(varSource) Then do something.
'
' AUTHOR: Christian Sawyer
' ====================================================================================
Function IsNoData(varVal2Check)
'Verify if varVal2Check contain something.
On Error Resume Next
If IsNull(varVal2Check) Or IsEmpty(varVal2Check) Then
IsNoData = True
Else
If IsDate(varVal2Check) Then
IsNoData = False
ElseIf varVal2Check = "" Then
IsNoData = True
ElseIf Not IsObject(varVal2Check) Then
IsNoData = False
Else
IsNoData = False
End If
End If
End Function 

Posted

Been playing a bit with some of my vbscripts this week so i'm quite fresh atm

 

If you change the following line:

Set objRootDSE = GetObject("LDAP://RootDSE")

To:

Set objRootDSE = GetObject("LDAP://ou=Network Computers,ou=ParentOU,dc=DOMAIN,dc=NAME")

Obviously adapting to your specific ad structure.

 

That should only query your networked computers ou and sub ou's.

 

Matt

Posted

Thanks,

I've changed the line you mentioned so that it reads:

' Connect to AD Root.
Set objRootDSE = GetObject("LDAP://ou=Network Computers,dc=Monmouth,dc=LOCAL")

but the line after it:

' Get domain name.
Set objDomain = GetObject("LDAP://" & objRootDSE.Get("DefaultNamingContext"))

now complains with the error 'The directory property cannot be found in the cache'.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...