Jump to content
Sign in to follow this  
lordofthestrings

first question I have to ask: LDAP is not working for me either..

Recommended Posts

All I would need is the LDAP to work in my case.. if anyone can help me get this going, I will see if I can contribute it to the AD UDF that allready exists..

thanks for any help offered guys!

L.

here's the vb script:

On Error Resume Next

NetBiosDomainName = "AXA-BE.INTRAXA"
Const ADS_NAME_TYPE_1779 = 1
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_UNKNOWN = 8

'make sure this script is executed via cscript engine'
Force "cscript"

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False

' Dictionary object to track group membership.
Set objMemberList = CreateObject("Scripting.Dictionary")
objMemberList.CompareMode = vbTextCompare


If Wscript.Arguments.Count < 1 Then
   str_computer=inputbox("Enter computername")
   if str_computer="" then
      Wscript.Quit(0)
   end if
End If

Wscript.echo "Processing " & str_computer & ":"
str_ldap_path=get_ldap_path(str_computer)
Set obj_Computer = GetObject(str_ldap_path)
If Err.Number <> 0 Then
    Wscript.Echo "computer not found in AD" 
    Wscript.Quit
End If


' Enumerate groups where computer is member. (recurse nestings)
wscript.echo "Enumerate AD USD groups where computer is member. (recurse nestings)"
objMemberOf=obj_computer.getex("MemberOf")
for each str_group in objMemberOf
    wscript.echo str_group
    Set obj_group = GetObject(get_ldap_path(last_token(first_token(str_group,","),"=")))
    Call EnumGroup(obj_group, vbtab)
next

wscript.echo ""
'query WMI for installed apps
list_installed_software(str_computer)

wscript.echo ""
wscript.echo "Hit enter to continue..."
user_input = wscript.stdin.readline

objConnection.Close
Set objGroup = Nothing
Set objRootDSE = Nothing
Set objCommand = Nothing
Set objConnection = Nothing

Sub EnumGroup(objadgroup, strOffset)
on error resume next
    obj_MemberOf=objADGroup.getex("MemberOf")
    if err.number then
     'wscript.echo "error getting member attrib"
     'skipping group if no members'
     err.clear
  else
      For Each strMember In obj_MemberOf
        Set obj_member = GetObject(get_ldap_path(last_token(first_token(strMember,","),"=")))
        If Not objMemberList(strMember) Then
          objMemberList(strMember) = True
          If UCase(Left(obj_Member.objectCategory, 8)) = "CN=GROUP" Then
            Wscript.Echo strOffset & obj_Member.sAMAccountName & " (Group)"
            Call EnumGroup(getobject(get_ldap_path(last_token(first_token(strMember,","),"="))), strOffset & vbtab)
          End If
        End If
      Next
  end if
      Set objMember = Nothing
      Set objRecordSet = Nothing
End Sub

Sub list_installed_software(str_computer)   
    on error resume next
    wscript.echo "Querying " & str_computer & " via WMI Win32_Product for installed apps."
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & str_Computer & "\root\cimv2")
    if err.number <> 0 then
        wscript.echo "WMI unavailable. Unable to query installed software."
        err.clear
        exit sub
    else
        Set colSoftware = objWMIService.ExecQuery ("Select * from Win32_Product")
        if err.number <> 0 then
            wscript.echo "Unable to query Win32_Product via WMI."
            err.clear
            exit sub   
        end if   
        For Each objSoftware in colSoftware
            wscript.echo     objSoftware.Caption & vbtab 
                             'objSoftware.Description & vbtab & _
                             'objSoftware.IdentifyingNumber & vbtab & _
                             'objSoftware.InstallDate2 & vbtab & _
                             'objSoftware.InstallLocation & vbtab & _
                             'objSoftware.InstallState & vbtab & _
                             'objSoftware.Name & vbtab & _
                             'objSoftware.PackageCache & vbtab & _
                             'objSoftware.SKUNumber & vbtab & _
                             'objSoftware.Vendor & vbtab & _
                             'objSoftware.Version
        Next
    end if
end sub



Function Get_LDAP_Path(strobj)  
    Set objConnection = CreateObject("ADODB.Connection")
    objConnection.Open "Provider=ADsDSOObject;"
    Set objCommand = CreateObject("ADODB.Command")
    objCommand.ActiveConnection = objConnection
    objCommand.CommandText = "<LDAP://" & NetBiosDomainName & ">;(cn=" & strobj & ");cn,objectcategory,distinguishedname;subtree"
    Set objRecordSet = objCommand.Execute
    If (objRecordset.recordcount > 0) Then
        While Not objRecordset.EOF
            Get_LDAP_Path="LDAP://" & objRecordset.Fields("distinguishedname")
            objRecordset.MoveNext
        Wend    
    End If
    'Get_LDAP_Path=""
End Function

function last_token(str_string,str_delimiter)
    arr_tokens = Split(str_string, str_delimiter, -1, 1)
    last_token=arr_tokens(ubound(arr_tokens))
end function

function first_token(str_string,str_delimiter)
    arr_tokens = Split(str_string, str_delimiter, -1, 1)
    first_token=arr_tokens(lbound(arr_tokens))
end function

Sub Force(sScriptEng)
' Forces this script to be run under the desired scripting host.
' Valid sScriptEng arguments are "wscript" or "cscript".
' If you don't supply a valid name, Force will switch hosts.
    If Lcase(Right(Wscript.FullName, 12)) = "\wscript.exe" Then
        'WScript.Echo "Running under WSCRIPT"
        If Instr(1, Wscript.FullName, sScriptEng, 1) = 0 Then
        'Need to switch to CSCRIPT
            CreateObject("Wscript.Shell").Run "cscript.exe " & Chr(34) & Wscript.ScriptFullName & Chr(34)
            Wscript.Quit
        End If
    Else
        'WScript.Echo "Running under CSCRIPT"
        If Instr(1, Wscript.FullName, sScriptEng, 1) = 0 Then
            'Need to switch to WSCRIPT
            CreateObject("Wscript.Shell").Run "wscript.exe " & Wscript.ScriptFullName
            Wscript.Quit
        End If
    End If
end sub

here's what I have so far...

#cs
'=========================================================================
'
' filename:         query_apps.vbs (.AU3)
'
' Date Created:     10/08/2006
' Date Modified:    13/12/2007
'
'=========================================================================
#ce
#include <Array.au3>

AutoItSetOption ( "RunErrorsFatal", 0)
#cs
On Error Resume Next

RunErrorsFatal Sets if the script should terminate with a fatal error if a Run/RunWait function fails due to bad paths/file not found/Bad login IDs:
1 = fatal error (default)
0 = silent error (@error set to 1) 
#ce
$NetBiosDomainName = "AXA-BE.INTRAXA"
Const $ADS_NAME_TYPE_1779 = 1
Const $ADS_NAME_INITTYPE_GC = 3
Const $ADS_NAME_TYPE_UNKNOWN = 8

;'make sure this script is executed via cscript engine'
;Force("cscript")

$objConnection = objCreate("ADODB.Connection")
$objCommand = objCreate("ADODB.Command")
$objConnection.Provider = ("ADsDSOObject")
$objConnection.Open ("Active Directory Provider")
$objCommand.ActiveConnection = $objConnection
$objCommand.Properties("Page Size") = 100
$objCommand.Properties("Timeout") = 30
$objCommand.Properties("Cache Results") = False

;' Dictionary object to track group membership.
$objMemberList = objCreate("Scripting.Dictionary")
$objMemberList.CompareMode = 1
;   var BinaryCompare = 0, TextCompare = 1;

if $CmdLine[0] < 1 Then
    $str_computer=inputbox("", "Enter computername")
    if $str_computer="" then
        Exit(1) ; No PC given
    endif
EndIf

;Wscript.echo "Processing " & str_computer & ":"
$objRecordSet.Fields("DistinguishedName").value
$str_ldap_path=ObjGet("LDAP://" & $str_computer)
msgbox(0,"strldappath",$str_ldap_path)
$obj_Computer = objGet($str_ldap_path)
msgbox(0,"", @error)
If @error <> 0 Then
    msgbox(0, "", "computer not found in AD")
    exit(1)
EndIf


;' Enumerate groups where computer is member. (recurse nestings)
msgbox(0,"", "Enumerate AD USD groups where computer is member. (recurse nestings)")
$objMemberOf=$obj_computer.getex("MemberOf")
for $str_group in $objMemberOf
msgbox(0, "",$str_group)
    $obj_group = objGet(get_ldap_path(last_token(first_token($str_group,","),"=")))
    EnumGroup($obj_group, @TAB)
next
#cs
wscript.echo ""
'query WMI for installed apps
list_installed_software(str_computer)

wscript.echo ""
wscript.echo "Hit enter to continue..."
user_input = wscript.stdin.readline

objConnection.Close
Set objGroup = Nothing
Set objRootDSE = Nothing
Set objCommand = Nothing
Set objConnection = Nothing
#ce
func EnumGroup($objadgroup, $strOffset)
    $obj_MemberOf=$objADGroup.getex("MemberOf")
    if @error then
;     'wscript.echo "error getting member attrib"
;     'skipping group if no members'
     SetError(0)
  else
      For $strMember In $obj_MemberOf
        $obj_member = ObjGet(get_ldap_path(last_token(first_token($strMember,","),"=")))
        If Not $objMemberList($strMember) Then
          $objMemberList($strMember)
          If StringIsUpper(stringLeft($obj_Member.objectCategory, 8)) = "CN=GROUP" Then
            MsgBox(0, "", $strOffset & $obj_Member.sAMAccountName & " (Group)")
            ;Wscript.Echo strOffset & obj_Member.sAMAccountName & " (Group)"
            EnumGroup(objget(get_ldap_path(last_token(first_token($strMember,","),"="))), $strOffset & $strOffset)
          EndIf
        EndIf
      Next
  endif
      $objMember = ""
      $objRecordSet = ""
EndFunc

Func list_installed_software($str_computer)   
    MsgBox(0,"", "Querying " & $str_computer & " via WMI Win32_Product for installed apps.")
    $objWMIService = objGet("winmgmts:{impersonationLevel=impersonate}!\\" & $str_Computer & "\root\cimv2")
    if @error <> 0 then
        msgbox(0,"","WMI unavailable. Unable to query installed software.")
        SetError(0)
        exit(1)
    else
        $colSoftware = $objWMIService.ExecQuery ("Select * from Win32_Product")
        if @error <> 0 then
            msgbox(0,"","Unable to query Win32_Product via WMI.")
            SetError(0)
            exit(1)
        endif     
        For $objSoftware in $colSoftware
            msgbox(0,"",     $objSoftware.Caption & @TAB )
            #cs
                             'objSoftware.Description & vbtab & _
                             'objSoftware.IdentifyingNumber & vbtab & _
                             'objSoftware.InstallDate2 & vbtab & _
                             'objSoftware.InstallLocation & vbtab & _
                             'objSoftware.InstallState & vbtab & _
                             'objSoftware.Name & vbtab & _
                             'objSoftware.PackageCache & vbtab & _
                             'objSoftware.SKUNumber & vbtab & _
                             'objSoftware.Vendor & vbtab & _
                             'objSoftware.Version
                             #ce
        Next
    endif
EndFunc



Func Get_LDAP_Path($strobj) 
    $objConnection = objCreate("ADODB.Connection")
    $objConnection.Open("Provider=ADsDSOObject;")
    $objCommand = objCreate("ADODB.Command")
    $objCommand.ActiveConnection = $objConnection
    $objCommand.CommandText = "<LDAP://" & $NetBiosDomainName & ">;(cn=" & $strobj & ");cn,objectcategory,distinguishedname;subtree"
    $objRecordSet = $objCommand.Execute
    If ($objRecordset.recordcount > 0) Then
        While Not $objRecordset.EOF
            $Get_LDAP_Path="LDAP://" & $objRecordset.Fields("distinguishedname")
            $objRecordset.MoveNext
        Wend    
    EndIf
    ;'Get_LDAP_Path=""
EndFunc

func last_token($str_string,$str_delimiter)
    $arr_tokens = StringSplit($str_string, $str_delimiter, 1)
    $last_token=$arr_tokens(ubound($arr_tokens))
endfunc

func first_token($str_string,$str_delimiter)
    $arr_tokens = stringSplit($str_string, $str_delimiter, 1)
    $first_token = _ArrayMin($arr_tokens)
endfuncoÝ÷ Ú«{l¶ º"0¢é])¶kzǧ¶)ìµæ¡÷îH$H=6®¶­sb6æ6ÇVFRfÇC´uT6öç7FçG2æS2fwC° ¤÷BgV÷C´uTöäWfVçDÖöFRgV÷C²Â¢5&Vvöâ2225D%B¶öFuT6V7Föâ222f÷&ÓФvÆö&Âb33c´w&÷WVçVÒÒuT7&VFRgV÷C´w&÷WVçVÖW&F÷"gV÷C²ÂcS"ÂSÂrÂR¤uT6WD&´6öÆ÷"¤uT6WDöäWfVçBb33c´uTôUdTåEô4Äõ4RÂgV÷C´w&÷WVçVÔ6Æ÷6RgV÷C²¤uT6WDöäWfVçBb33c´uTôUdTåEôÔäÔ¤RÂgV÷C´w&÷WVçVÔÖæÖ¦RgV÷C²¤uT6WDöäWfVçBb33c´uTôUdTåEôÔÔ¤RÂgV÷C´w&÷WVçVÔÖÖ¦RgV÷C²¤uT6WDöäWfVçBb33c´uTôUdTåEõ$U5Dõ$RÂgV÷C´w&÷WVçVÕ&W7F÷&RgV÷C²¤vÆö&Âb33c´&÷w&÷W2ÒuT7G&Ä7&VFTÆ7BgV÷C²gV÷C²ÂbÂ#ÂcrÂ3C¤uT7G&Å6WDFFÓÂgV÷C´ÆæSÄÆæS'ÄÆæS2gV÷C²¤uT7G&Å6WDföçBÓÂ"ÂCÂÂgV÷CµFÖW2æWr&öÖâgV÷C²¤uT7G&Å6WD6öÆ÷"ÓÂdddddb¤uT7G&Å6WD&´6öÆ÷"Ó¤uT7G&Å6WDöäWfVçBÓÂgV÷C´&÷w&÷W46Æ6²gV÷C²¤vÆö&Âb33c´&÷6ö×æÖRÒuT7G&Ä7&VFTÆ7BgV÷C²gV÷C²Â#Â3"ÂsrÂ#¤uT7G&Å6WDFFÓÂgV÷Cµ4æÖSgV÷C²¤uT7G&Å6WDföçBÓÂ"ÂCÂÂgV÷C´&Â&Æ6²gV÷C²¤uT7G&Å6WDöäWfVçBÓÂgV÷C´&÷6ö×æÖT6Æ6²gV÷C²¤vÆö&Âb33c´Æ&VÄ6ö×æÖRÒuT7G&Ä7&VFTÆ&VÂgV÷C´6ö×WFW"æÖS¢gV÷C²ÂSbÂCÂCÂ#b¤uT7G&Å6WDföçBÓÂBÂÂ"ÂgV÷CµFÖW2æWr&öÖâgV÷C²¤uT7G&Å6WD6öÆ÷"ÓÂdddc¤uT7G&Å6WD&´6öÆ÷"Ó¤uT7G&Å6WDöäWfVçBÓÂgV÷C´Æ&VÄ6ö×æÖT6Æ6²gV÷C²¤vÆö&Âb33c´Æ&VÄw&÷W2ÒuT7G&Ä7&VFTÆ&VÂgV÷C´2ÖVÖ&W"öbFRföÆÆ÷værw&÷W3¢gV÷C²Â3"ÂÂ#3rÂ#2¤uT7G&Å6WDföçBÓÂ"ÂÂ"ÂgV÷CµFÖW2æWr&öÖâgV÷C²¤uT7G&Å6WD6öÆ÷"ÓÂdddc¤uT7G&Å6WD&´6öÆ÷"Ó¤uT7G&Å6WDöäWfVçBÓÂgV÷C´Æ&VÄw&÷W46Æ6²gV÷C²¤uT6WE7FFR5uõ4õr¢4VæE&Vvöâ222TäB¶öFuT6V7Föâ220 ¥vÆR 6ÆVW¥tVæ@  ¤gVæ2&÷6ö×æÖT6Æ6² ¤VæDgVæ0  ¤gVæ2&÷w&÷W46Æ6² ¤VæDgVæ0  ¤gVæ2w&÷WVçVÔ6Æ÷6R¤W@¤VæDgVæ0  ¤gVæ2w&÷WVçVÔÖÖ¦R¤VæDgVæ0  ¤gVæ2w&÷WVçVÔÖæÖ¦R ¤VæDgVæ0  ¤gVæ2w&÷WVçVÕ&W7F÷&R ¤VæDgVæ0  ¤gVæ2Æ&VÄ6ö×æÖT6Æ6² ¤VæDgVæ0  ¤gVæ2Æ&VÄw&÷W46Æ6² ¤VæDgVæ0

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×
×
  • Create New...