cherdeg Posted November 27, 2008 Posted November 27, 2008 (edited) Just try exactly this code (NO changes) in a separate script. As results 1st the array is being displayed, 2nd the netbios-name of the 1st DC. expandcollapse popup#include <Array.au3> Global $a_DomainControllers $a_DomainControllers = GetDC() If IsArray($a_DomainControllers) Then _ArrayDisplay($a_DomainControllers) $a_cnStrings = StringSplit($a_DomainControllers[1], ",") $s_NeededValue = StringTrimLeft($a_cnStrings[1], 3) MsgBox("", "TEST", $s_NeededValue) Else MsgBox("", "TEST", $a_DomainControllers) ; "0" Exit EndIf ; The function GetDC() checks for the DC of the current domain ; ================================================================================================== Func GetDC() Global $o_Connection = ObjCreate("ADODB.Connection") ; Create COM object to AD $o_Connection.ConnectionString = "Provider=ADsDSOObject" $o_Connection.Open("Active Directory Provider") ; Open connection to AD Global $o_RootDSE = ObjGet("LDAP://RootDSE") Global $s_DNSDomain = $o_RootDSE.Get("defaultNamingContext") ; Retrieve the current AD domain name Global $s_HostServer = $o_RootDSE.Get("dnsHostName") ; Retrieve the name of the connected DC Global $s_Configuration = $o_RootDSE.Get("ConfigurationNamingContext") ; Retrieve the Configuration naming context Global $o_OpenDS = ObjGet("LDAP:") $o_CMD = ObjCreate("ADODB.Command") $o_CMD.ActiveConnection = $o_Connection $o_CMD.Properties("Page Size") = 1000 $o_CMD.Properties("Searchscope") = 2 $o_CMD.CommandText = "Select distinguishedName FROM 'LDAP://" & $s_HostServer & "/ou=Domain Controllers," & $s_DNSDomain & "' WHERE objectclass='computer'" $o_RecordSet = $o_CMD.Execute Local $s_DC[$o_RecordSet.RecordCount + 1] $o_RecordSet.MoveFirst Do $s_DC[0] += 1 $o_CMD.CommandText = "<LDAP://" & $s_HostServer & "/" & $o_RecordSet.Fields("distinguishedName" ).Value & ">;;serverReferenceBL;Range=0-*;base" $o_RecordSet2 = $o_CMD.Execute $o_RecordSet2.MoveFirst Do $temparray = $o_RecordSet2.Fields(0).Value $s_DC[$s_DC[0]] = $temparray[0] $o_RecordSet2.MoveNext Until $o_RecordSet2.EOF $o_RecordSet.MoveNext Until $o_RecordSet.EOF $o_CMD = 0 $o_RecordSet = 0 Return $s_DC EndFunc ;==>_ADListDomainControllers Edited November 27, 2008 by cherdeg
bourny Posted November 27, 2008 Author Posted November 27, 2008 What I've found so far:I think we have different versions of adfunctions.au3. The line numbers and the code on this line don't fit with my version. Therefore I'll attach my version of adfunctions.au3When using _ADListDomainControllers you have to provide the Array as an argument. The function always seem to return 0. So a call like "$DCList = _ADListDomainControllers($DCList) overwrites the $DCList Array which has been populated by the function with the returncode. You should call the function without assignment "_ADListDomainControllers($DCList)"If you still have problems could you please run my script from posting 25 with the attached adfunctions.au3 and return the console output?Do you run your tests on a Server directly? The scripts should run fine from any PC.I have set up a new XP machine with a new install of the latest AutoIt and SCite applications - Then donloaded your copy of AdFunctions and the script from post 25. Results are the Same - Fails with the same error ...What am I doing wrong ... This defies all logic. It has the list of DC`s but for some reason my machines will not net me assign the object $o_RecordSet2.Fields(0).Value to an array ....
bourny Posted November 27, 2008 Author Posted November 27, 2008 Just try exactly this code (NO changes) in a separate script. As results 1st the array is being displayed, 2nd the netbios-name of the 1st DC. expandcollapse popup#include <Array.au3> Global $a_DomainControllers $a_DomainControllers = GetDC() If IsArray($a_DomainControllers) Then _ArrayDisplay($a_DomainControllers) $a_cnStrings = StringSplit($a_DomainControllers[1], ",") $s_NeededValue = StringTrimLeft($a_cnStrings[1], 3) MsgBox("", "TEST", $s_NeededValue) Else MsgBox("", "TEST", $a_DomainControllers) ; "0" Exit EndIf ; The function GetDC() checks for the DC of the current domain ; ================================================================================================== Func GetDC() Global $o_Connection = ObjCreate("ADODB.Connection") ; Create COM object to AD $o_Connection.ConnectionString = "Provider=ADsDSOObject" $o_Connection.Open("Active Directory Provider") ; Open connection to AD Global $o_RootDSE = ObjGet("LDAP://RootDSE") Global $s_DNSDomain = $o_RootDSE.Get("defaultNamingContext") ; Retrieve the current AD domain name Global $s_HostServer = $o_RootDSE.Get("dnsHostName") ; Retrieve the name of the connected DC Global $s_Configuration = $o_RootDSE.Get("ConfigurationNamingContext") ; Retrieve the Configuration naming context Global $o_OpenDS = ObjGet("LDAP:") $o_CMD = ObjCreate("ADODB.Command") $o_CMD.ActiveConnection = $o_Connection $o_CMD.Properties("Page Size") = 1000 $o_CMD.Properties("Searchscope") = 2 $o_CMD.CommandText = "Select distinguishedName FROM 'LDAP://" & $s_HostServer & "/ou=Domain Controllers," & $s_DNSDomain & "' WHERE objectclass='computer'" $o_RecordSet = $o_CMD.Execute Local $s_DC[$o_RecordSet.RecordCount + 1] $o_RecordSet.MoveFirst Do $s_DC[0] += 1 $o_CMD.CommandText = "<LDAP://" & $s_HostServer & "/" & $o_RecordSet.Fields("distinguishedName" ).Value & ">;;serverReferenceBL;Range=0-*;base" $o_RecordSet2 = $o_CMD.Execute $o_RecordSet2.MoveFirst Do $temparray = $o_RecordSet2.Fields(0).Value $s_DC[$s_DC[0]] = $temparray[0] $o_RecordSet2.MoveNext Until $o_RecordSet2.EOF $o_RecordSet.MoveNext Until $o_RecordSet.EOF $o_CMD = 0 $o_RecordSet = 0 Return $s_DC EndFunc ;==>_ADListDomainControllers Same Error (53) : ==> Subscript used with non-Array variable.: $s_DC[$s_DC[0]] = $temparray[0] $s_DC[$s_DC[0]] = $temparray^ ERROR
water Posted November 27, 2008 Posted November 27, 2008 To check if there are any other problems you could download ADExplorer from Sysinternals (now M$). No installation required - you simply run the EXE. * Press OK on the connection screen. * Open you company's tree e.g. dc=microsoft,dc=com * open OU=Domain Controllers Now you should see the list of available Domain Controllers. This list should be returned by the autoit script. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
bourny Posted November 27, 2008 Author Posted November 27, 2008 To check if there are any other problems you could download ADExplorer from Sysinternals (now M$). No installation required - you simply run the EXE. * Press OK on the connection screen. * Open you company's tree e.g. dc=microsoft,dc=com * open OU=Domain Controllers Now you should see the list of available Domain Controllers. This list should be returned by the autoit script. All works fine - The list is returned bu the script - If I do the following I get the output with all the server names in a loop. I then get an empty array due to the fact I remmed out the 2 lines for $temparray to get the script to stop falling over ... Do $s_DC[0] += 1 $o_CMD.CommandText = "<LDAP://" & $s_HostServer & "/" & $o_RecordSet.Fields("distinguishedName" ).Value & ">;;serverReferenceBL;Range=0-*;base" $o_RecordSet2 = $o_CMD.Execute msgbox(0, "", $o_RecordSet2.Fields(0).Value) $o_RecordSet2.MoveFirst Do ;$temparray = $o_RecordSet2.Fields(0).Value ;$s_DC[$s_DC[0]] = $temparray[0] $o_RecordSet2.MoveNext Until $o_RecordSet2.EOF $o_RecordSet.MoveNext Until $o_RecordSet.EOF
water Posted November 27, 2008 Posted November 27, 2008 Would you be so kind and insert the following line at the beginning of your script: #AutoIt3Wrapper_Run_Debug_Mode=y Then run the script and return the console output? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
bourny Posted November 27, 2008 Author Posted November 27, 2008 Would you be so kind and insert the following line at the beginning of your script: #AutoIt3Wrapper_Run_Debug_Mode=y Then run the script and return the console output? Ok - I get the following !> Starting in DebugMode.. Line: @error-@extended: Line syntax 0001: 0-0: #AutoIt3Wrapper_Run_Debug_Mode=y 0004: 0-0: #include <adfunctions.au3> 0005: 0-0: #include <array.au3> ; This line can be deleted 0006: 0-0: Global $DCList, $LastLogin=0 0007: 0-0: _ADListDomainControllers($DCList) C:\Program Files\AutoIt3\Include\adfunctions.au3 (1093) : ==> Subscript used with non-Array variable.: $DCList[$DCList[0]] = $temparray[0] $DCList[$DCList[0]] = $temparray^ ERROR ->14:23:12 AutoIT3.exe ended.rc:1 +>14:23:13 AutoIt3Wrapper Finished >Exit code: 1 Time: 2.247
cherdeg Posted November 27, 2008 Posted November 27, 2008 I really dunno what you guys are looking for. This one works perfectly (but maybe your infrastructure has problems?), and so I completed it to match the features requested by the OP (get the time of the last login of a given user), just give it a try: expandcollapse popup#include <Array.au3> Global $o_Connection = ObjCreate("ADODB.Connection") ; Create COM object to AD $o_Connection.ConnectionString = "Provider=ADsDSOObject" $o_Connection.Open("Active Directory Provider") ; Open connection to AD Global $o_RootDSE = ObjGet("LDAP://RootDSE") Global $s_DNSDomain = $o_RootDSE.Get("defaultNamingContext") ; Retrieve the current AD domain name Global $s_HostServer = $o_RootDSE.Get("dnsHostName") ; Retrieve the name of the connected DC Global $s_Configuration = $o_RootDSE.Get("ConfigurationNamingContext") ; Retrieve the Configuration naming context Global $o_OpenDS = ObjGet("LDAP:") Global $alt_userid = "" Global $alt_password = "" Global $a_DomainControllers Global $i_LastLogin=0 $a_DomainControllers = GetDC() If IsArray($a_DomainControllers) Then _ArrayDisplay($a_DomainControllers) $a_cnStrings = StringSplit($a_DomainControllers[1], ",") $s_HostServer = StringTrimLeft($a_cnStrings[1], 3) MsgBox("", "TEST", $s_HostServer) Else MsgBox("", "TEST", $a_DomainControllers) ; "0" Exit EndIf For $i =1 to $a_DomainControllers[0] $s_Tmp = StringSplit($a_DomainControllers[$i],",") $s_Tmp = StringSplit($s_Tmp[1],"CN=",1) $s_HostServer = $s_Tmp[2] $s_Tmp = _ADGetLastLoginDate(@username) MsgBox("", "TEST", $s_HostServer & ": " & $s_Tmp & @lf) If $s_Tmp > $i_LastLogin Then $i_LastLogin = $s_Tmp Next ; The function _GetLogin($s_HostServer,$s_SAMaccountName) checks for the time of the last login of the given user to a DC ; ================================================================================================== Func _ADGetLastLoginDate($s_user) If _ADObjectExists($s_user) = 0 Then Return 0 $s_Query = "<LDAP://" & $s_HostServer & "/" & $s_DNSDomain & ">;(sAMAccountName=" & $s_user & ");ADsPath;subtree" $o_RecordSet = $o_Connection.Execute($s_Query) ; Retrieve the FQDN for the object $s_ldapEntry = $o_RecordSet.fields(0).value $o_COMobject = _ADObjGet($s_ldapEntry) ; Retrieve the COM Object for the object $s_result = $o_COMobject.LastLogin $o_COMobject.PurgePropertyList If $s_result = "" Then Return "" Else Return $s_result EndIf EndFunc ;==>_ADGetLastLoginDate ; The function GetDC() checks for the DC of the current domain ; ================================================================================================== Func GetDC() $o_CMD = ObjCreate("ADODB.Command") $o_CMD.ActiveConnection = $o_Connection $o_CMD.Properties("Page Size") = 1000 $o_CMD.Properties("Searchscope") = 2 $o_CMD.CommandText = "Select distinguishedName FROM 'LDAP://" & $s_HostServer & "/ou=Domain Controllers," & $s_DNSDomain & "' WHERE objectclass='computer'" $o_RecordSet = $o_CMD.Execute Local $s_DC[$o_RecordSet.RecordCount + 1] $o_RecordSet.MoveFirst Do $s_DC[0] += 1 $o_CMD.CommandText = "<LDAP://" & $s_HostServer & "/" & $o_RecordSet.Fields("distinguishedName" ).Value & ">;;serverReferenceBL;Range=0-*;base" $o_RecordSet2 = $o_CMD.Execute $o_RecordSet2.MoveFirst Do $temparray = $o_RecordSet2.Fields(0).Value $s_DC[$s_DC[0]] = $temparray[0] $o_RecordSet2.MoveNext Until $o_RecordSet2.EOF $o_RecordSet.MoveNext Until $o_RecordSet.EOF $o_CMD = 0 $o_RecordSet = 0 Return $s_DC EndFunc ;==>_ADListDomainControllers ; _ADObjGet ; Takes a FQDN and returns the LDAP object from that ; Will use the alternative credentials $alt_userid/$alt_password if they exist. ; ================================================================================================== Func _ADObjGet($dn) If $alt_userid = "" Then Return ObjGet($dn) Else Return $o_OpenDS.OpenDSObject($dn, $alt_userid, $alt_password, BitOR(0x200, 0x1)) EndIf EndFunc ;==>_ADObjGet ; _ADObjectExists ; Takes an object name (SamAccountName without leading 'CN=') ; Returns 1 if the object exists in the tree, 0 otherwise ; ================================================================================================== Func _ADObjectExists($o_object) $s_Query = "<LDAP://" & $s_HostServer & "/" & $s_DNSDomain & ">;(sAMAccountName=" & $o_object & ");ADsPath;subtree" $o_RecordSet = $o_Connection.Execute($s_Query) ; Retrieve the FQDN for the group, if it exists If $o_RecordSet.RecordCount = 1 Then $o_RecordSet = 0 Return 1 Else $o_RecordSet = 0 Return 0 EndIf EndFunc ;==>_ADObjectExists
water Posted November 27, 2008 Posted November 27, 2008 Could you please do the same with cherdeg's code My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
bourny Posted November 27, 2008 Author Posted November 27, 2008 Could you please do the same with cherdeg's code Fails ... I cannot understand how it can be infrastructure when it pulls a list of all the DC`s - just fails to create an array from $objRecSet2.Fields(0).Value Here is the Debug !> Starting in DebugMode.. Line: @error-@extended: Line syntax 0001: 0-0: #AutoIt3Wrapper_Run_Debug_Mode=y 0003: 0-0: #include <Array.au3> 0005: 0-0: Global $o_Connection = ObjCreate("ADODB.Connection") ; Create COM object to AD 0006: 0-0: $o_Connection.ConnectionString = "Provider=ADsDSOObject" 0007: 0-0: $o_Connection.Open("Active Directory Provider") ; Open connection to AD 0009: 0-0: Global $o_RootDSE = ObjGet("LDAP://RootDSE") 0010: 0-0: Global $s_DNSDomain = $o_RootDSE.Get("defaultNamingContext") ; Retrieve the current AD domain name 0011: 0-0: Global $s_HostServer = $o_RootDSE.Get("dnsHostName") ; Retrieve the name of the connected DC 0012: 0-0: Global $s_Configuration = $o_RootDSE.Get("ConfigurationNamingContext") ; Retrieve the Configuration naming context 0013: 0-0: Global $o_OpenDS = ObjGet("LDAP:") 0014: 0-0: Global $alt_userid = "" 0015: 0-0: Global $alt_password = "" 0017: 0-0: Global $a_DomainControllers 0018: 0-0: Global $i_LastLogin=0 0023: 0-0: $a_DomainControllers = GetDC() 0068: 0-0: $o_CMD = ObjCreate("ADODB.Command") 0069: 0-0: $o_CMD.ActiveConnection = $o_Connection 0070: 0-0: $o_CMD.Properties("Page Size") = 1000 0071: 0-0: $o_CMD.Properties("Searchscope") = 2 0073: 0-0: $o_CMD.CommandText = "Select distinguishedName FROM "LDAP://" & $s_HostServer & "/ou=Domain Controllers," & $s_DNSDomain & "" WHERE objectclass="computer"" 0075: 0-0: $o_RecordSet = $o_CMD.Execute 0077: 0-0: Local $s_DC[$o_RecordSet.RecordCount + 1] 0078: 0-0: $o_RecordSet.MoveFirst 0080: 0-0: Do 0081: 0-0: $s_DC[0] += 1 0082: 0-0: $o_CMD.CommandText = "<LDAP://" & $s_HostServer & "/" & $o_RecordSet.Fields("distinguishedName" ).Value & ">;;serverReferenceBL;Range=0-*;base" 0083: 0-0: $o_RecordSet2 = $o_CMD.Execute 0085: 0-0: $o_RecordSet2.MoveFirst 0086: 0-0: Do 0087: 0-0: $temparray = $o_RecordSet2.Fields(0).Value 0088: 0-0: $s_DC[$s_DC[0]] = $temparray[0] C:\Documents and Settings\603710\Desktop\test7_DebugIt.au3 (278) : ==> Subscript used with non-Array variable.: $s_DC[$s_DC[0]] = $temparray[0] $s_DC[$s_DC[0]] = $temparray^ ERROR ->14:32:39 AutoIT3.exe ended.rc:1 +>14:32:41 AutoIt3Wrapper Finished >Exit code: 1 Time: 1.938
water Posted November 27, 2008 Posted November 27, 2008 Sorry, but you don't use the code (from posting # 41) that I mentioned. Could you please try again. To solve the problem it's vital that we are all talking about the same code My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
bourny Posted November 27, 2008 Author Posted November 27, 2008 Sorry, but you don't use the code (from posting # 41) that I mentioned. Could you please try again. To solve the problem it's vital that we are all talking about the same code Sorry I thought you meant the code above your last request in post 48 Here is the debug from post 41 expandcollapse popup[/code] !> Starting in DebugMode.. Line: @error-@extended: Line syntax 0001: 0-0: #AutoIt3Wrapper_Run_Debug_Mode=y 0003: 0-0: #include <Array.au3> 0005: 0-0: Global $a_DomainControllers 0008: 0-0: $a_DomainControllers = GetDC() 0025: 0-0: Global $o_Connection = ObjCreate("ADODB.Connection"); Create COM object to AD 0026: 0-0: $o_Connection.ConnectionString = "Provider=ADsDSOObject" 0027: 0-0: $o_Connection.Open("Active Directory Provider"); Open connection to AD 0029: 0-0: Global $o_RootDSE = ObjGet("LDAP://RootDSE") 0030: 0-0: Global $s_DNSDomain = $o_RootDSE.Get("defaultNamingContext"); Retrieve the current AD domain name 0031: 0-0: Global $s_HostServer = $o_RootDSE.Get("dnsHostName"); Retrieve the name of the connected DC 0032: 0-0: Global $s_Configuration = $o_RootDSE.Get("ConfigurationNamingContext"); Retrieve the Configuration naming context 0033: 0-0: Global $o_OpenDS = ObjGet("LDAP:") 0035: 0-0: $o_CMD = ObjCreate("ADODB.Command") 0036: 0-0: $o_CMD.ActiveConnection = $o_Connection 0037: 0-0: $o_CMD.Properties("Page Size") = 1000 0038: 0-0: $o_CMD.Properties("Searchscope") = 2 0040: 0-0: $o_CMD.CommandText = "Select distinguishedName FROM "LDAP://" & $s_HostServer & "/ou=Domain Controllers," & $s_DNSDomain & "" WHERE objectclass="computer"" 0042: 0-0: $o_RecordSet = $o_CMD.Execute 0044: 0-0: Local $s_DC[$o_RecordSet.RecordCount + 1] 0045: 0-0: $o_RecordSet.MoveFirst 0047: 0-0: Do 0048: 0-0: $s_DC[0] += 1 0049: 0-0: $o_CMD.CommandText = "<LDAP://" & $s_HostServer & "/" & $o_RecordSet.Fields("distinguishedName" ).Value & ">;;serverReferenceBL;Range=0-*;base" 0050: 0-0: $o_RecordSet2 = $o_CMD.Execute 0052: 0-0: $o_RecordSet2.MoveFirst 0053: 0-0: Do 0054: 0-0: $temparray = $o_RecordSet2.Fields(0).Value 0055: 0-0: $s_DC[$s_DC[0]] = $temparray[0] C:\Documents and Settings\603710\Desktop\test7_DebugIt.au3 (170) : ==> Subscript used with non-Array variable.: $s_DC[$s_DC[0]] = $temparray[0] $s_DC[$s_DC[0]] = $temparray^ ERROR ->14:46:33 AutoIT3.exe ended.rc:1 +>14:46:34 AutoIt3Wrapper Finished >Exit code: 1 Time: 1.945 [code]
water Posted November 27, 2008 Posted November 27, 2008 As there is no error with "$temparray = $o_RecordSet2.Fields(0).Value" the value doesn't seem to be an array in your case. Could you please replace $s_DC[$s_DC[0]] = $temparray[0]oÝ÷ Û«¢+ØÀÌØíÍ} lÀÌØíÍ} lÁutôÀÌØíѵÁÉÉä)½¹Í½±ÝÉ¥Ñ ÀÌØíѵÁÉÉäµÀ챤and return the console output? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
bourny Posted November 27, 2008 Author Posted November 27, 2008 As there is no error with "$temparray = $o_RecordSet2.Fields(0).Value" the value doesn't seem to be an array in your case. Could you please replace $s_DC[$s_DC[0]] = $temparray[0]oÝ÷ Û«¢+ØÀÌØíÍ} lÀÌØíÍ} lÁutôÀÌØíѵÁÉÉä)½¹Í½±ÝÉ¥Ñ ÀÌØíѵÁÉÉäµÀ챤and return the console output? WELL DONE !!!!!! I get an array displayed with the DC`s listed .... Here is the debug with my domain names and Servers renamed to protect them !> Starting in DebugMode.. Line: @error-@extended: Line syntax 0001: 0-0: #AutoIt3Wrapper_Run_Debug_Mode=y 0003: 0-0: #include <Array.au3> 0005: 0-0: Global $a_DomainControllers 0008: 0-0: $a_DomainControllers = GetDC() 0025: 0-0: Global $o_Connection = ObjCreate("ADODB.Connection") ; Create COM object to AD 0026: 0-0: $o_Connection.ConnectionString = "Provider=ADsDSOObject" 0027: 0-0: $o_Connection.Open("Active Directory Provider") ; Open connection to AD 0029: 0-0: Global $o_RootDSE = ObjGet("LDAP://RootDSE") 0030: 0-0: Global $s_DNSDomain = $o_RootDSE.Get("defaultNamingContext") ; Retrieve the current AD domain name 0031: 0-0: Global $s_HostServer = $o_RootDSE.Get("dnsHostName") ; Retrieve the name of the connected DC 0032: 0-0: Global $s_Configuration = $o_RootDSE.Get("ConfigurationNamingContext") ; Retrieve the Configuration naming context 0033: 0-0: Global $o_OpenDS = ObjGet("LDAP:") 0035: 0-0: $o_CMD = ObjCreate("ADODB.Command") 0036: 0-0: $o_CMD.ActiveConnection = $o_Connection 0037: 0-0: $o_CMD.Properties("Page Size") = 1000 0038: 0-0: $o_CMD.Properties("Searchscope") = 2 0040: 0-0: $o_CMD.CommandText = "Select distinguishedName FROM "LDAP://" & $s_HostServer & "/ou=Domain Controllers," & $s_DNSDomain & "" WHERE objectclass="computer"" 0042: 0-0: $o_RecordSet = $o_CMD.Execute 0044: 0-0: Local $s_DC[$o_RecordSet.RecordCount + 1] 0045: 0-0: $o_RecordSet.MoveFirst 0047: 0-0: Do 0048: 0-0: $s_DC[0] += 1 0049: 0-0: $o_CMD.CommandText = "<LDAP://" & $s_HostServer & "/" & $o_RecordSet.Fields("distinguishedName" ).Value & ">;;serverReferenceBL;Range=0-*;base" 0050: 0-0: $o_RecordSet2 = $o_CMD.Execute 0052: 0-0: $o_RecordSet2.MoveFirst 0053: 0-0: Do 0054: 0-0: $temparray = $o_RecordSet2.Fields(0).Value 0056: 0-0: $s_DC[$s_DC[0]] = $temparray 0057: 0-0: consolewrite($temparray & @lf) CN=DC3,CN=Servers,CN=SITE1,CN=Sites,CN=Configuration,DC=MYDOMAIN,DC=co,DC=uk 0058: 0-0: $o_RecordSet2.MoveNext 0059: 0-0: Until $o_RecordSet2.EOF 0061: 0-0: $o_RecordSet.MoveNext 0062: 0-0: Until $o_RecordSet.EOF 0048: 0-0: $s_DC[0] += 1 0049: 0-0: $o_CMD.CommandText = "<LDAP://" & $s_HostServer & "/" & $o_RecordSet.Fields("distinguishedName" ).Value & ">;;serverReferenceBL;Range=0-*;base" 0050: 0-0: $o_RecordSet2 = $o_CMD.Execute 0052: 0-0: $o_RecordSet2.MoveFirst 0053: 0-0: Do 0054: 0-0: $temparray = $o_RecordSet2.Fields(0).Value 0056: 0-0: $s_DC[$s_DC[0]] = $temparray 0057: 0-0: consolewrite($temparray & @lf) CN=DC4,CN=Servers,CN=SITE1,CN=Sites,CN=Configuration,DC=MYDOM,DC=co,DC=uk 0058: 0-0: $o_RecordSet2.MoveNext 0059: 0-0: Until $o_RecordSet2.EOF 0061: 0-0: $o_RecordSet.MoveNext 0062: 0-0: Until $o_RecordSet.EOF 0048: 0-0: $s_DC[0] += 1 0049: 0-0: $o_CMD.CommandText = "<LDAP://" & $s_HostServer & "/" & $o_RecordSet.Fields("distinguishedName" ).Value & ">;;serverReferenceBL;Range=0-*;base" 0050: 0-0: $o_RecordSet2 = $o_CMD.Execute 0052: 0-0: $o_RecordSet2.MoveFirst 0053: 0-0: Do 0054: 0-0: $temparray = $o_RecordSet2.Fields(0).Value 0056: 0-0: $s_DC[$s_DC[0]] = $temparray 0057: 0-0: consolewrite($temparray & @lf) CN=DC10,CN=Servers,CN=SITE2,CN=Sites,CN=Configuration,DC=MYDOM,DC=co,DC=uk 0058: 0-0: $o_RecordSet2.MoveNext 0059: 0-0: Until $o_RecordSet2.EOF 0061: 0-0: $o_RecordSet.MoveNext 0062: 0-0: Until $o_RecordSet.EOF 0048: 0-0: $s_DC[0] += 1 0049: 0-0: $o_CMD.CommandText = "<LDAP://" & $s_HostServer & "/" & $o_RecordSet.Fields("distinguishedName" ).Value & ">;;serverReferenceBL;Range=0-*;base" 0050: 0-0: $o_RecordSet2 = $o_CMD.Execute 0052: 0-0: $o_RecordSet2.MoveFirst 0053: 0-0: Do 0054: 0-0: $temparray = $o_RecordSet2.Fields(0).Value 0056: 0-0: $s_DC[$s_DC[0]] = $temparray 0057: 0-0: consolewrite($temparray & @lf) CN=DC9,CN=Servers,CN=SITE3,CN=Sites,CN=Configuration,DC=MYDOM,DC=co,DC=uk 0058: 0-0: $o_RecordSet2.MoveNext 0059: 0-0: Until $o_RecordSet2.EOF 0061: 0-0: $o_RecordSet.MoveNext 0062: 0-0: Until $o_RecordSet.EOF 0048: 0-0: $s_DC[0] += 1 0049: 0-0: $o_CMD.CommandText = "<LDAP://" & $s_HostServer & "/" & $o_RecordSet.Fields("distinguishedName" ).Value & ">;;serverReferenceBL;Range=0-*;base" 0050: 0-0: $o_RecordSet2 = $o_CMD.Execute 0052: 0-0: $o_RecordSet2.MoveFirst 0053: 0-0: Do 0054: 0-0: $temparray = $o_RecordSet2.Fields(0).Value 0056: 0-0: $s_DC[$s_DC[0]] = $temparray 0057: 0-0: consolewrite($temparray & @lf) CN=DC8,CN=Servers,CN=SITE4,CN=Sites,CN=Configuration,DC=MYDOM,DC=co,DC=uk 0058: 0-0: $o_RecordSet2.MoveNext 0059: 0-0: Until $o_RecordSet2.EOF 0061: 0-0: $o_RecordSet.MoveNext 0062: 0-0: Until $o_RecordSet.EOF 0048: 0-0: $s_DC[0] += 1 0049: 0-0: $o_CMD.CommandText = "<LDAP://" & $s_HostServer & "/" & $o_RecordSet.Fields("distinguishedName" ).Value & ">;;serverReferenceBL;Range=0-*;base" 0050: 0-0: $o_RecordSet2 = $o_CMD.Execute 0052: 0-0: $o_RecordSet2.MoveFirst 0053: 0-0: Do 0054: 0-0: $temparray = $o_RecordSet2.Fields(0).Value 0056: 0-0: $s_DC[$s_DC[0]] = $temparray 0057: 0-0: consolewrite($temparray & @lf) CN=DC1,CN=Servers,CN=SITE2,CN=Sites,CN=Configuration,DC=MYDOM,DC=co,DC=uk 0058: 0-0: $o_RecordSet2.MoveNext 0059: 0-0: Until $o_RecordSet2.EOF 0061: 0-0: $o_RecordSet.MoveNext 0062: 0-0: Until $o_RecordSet.EOF 0048: 0-0: $s_DC[0] += 1 0049: 0-0: $o_CMD.CommandText = "<LDAP://" & $s_HostServer & "/" & $o_RecordSet.Fields("distinguishedName" ).Value & ">;;serverReferenceBL;Range=0-*;base" 0050: 0-0: $o_RecordSet2 = $o_CMD.Execute 0052: 0-0: $o_RecordSet2.MoveFirst 0053: 0-0: Do 0054: 0-0: $temparray = $o_RecordSet2.Fields(0).Value 0056: 0-0: $s_DC[$s_DC[0]] = $temparray 0057: 0-0: consolewrite($temparray & @lf) CN=DC2,CN=Servers,CN=SITE2,CN=Sites,CN=Configuration,DC=MYDOM,DC=co,DC=uk 0058: 0-0: $o_RecordSet2.MoveNext 0059: 0-0: Until $o_RecordSet2.EOF 0061: 0-0: $o_RecordSet.MoveNext 0062: 0-0: Until $o_RecordSet.EOF 0064: 0-0: $o_CMD = 0 0065: 0-0: $o_RecordSet = 0 0066: 0-0: Return $s_DC 0011: 0-0: If IsArray($a_DomainControllers) Then 0012: 0-0: _ArrayDisplay($a_DomainControllers) 0013: 0-0: $a_cnStrings = StringSplit($a_DomainControllers[1], ",") 0014: 0-0: $s_NeededValue = StringTrimLeft($a_cnStrings[1], 3) 0015: 0-0: MsgBox("", "TEST", $s_NeededValue) 0016: 0-0: Else 0024: 0-0: Func GetDC() +>15:09:23 AutoIT3.exe ended.rc:0 +>15:09:24 AutoIt3Wrapper Finished >Exit code: 0 Time: 8.469
water Posted November 27, 2008 Posted November 27, 2008 Crazy Must be some kind of configuration difference on the AD side. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
bourny Posted November 27, 2008 Author Posted November 27, 2008 Crazy Must be some kind of configuration difference on the AD side.This must happen for other people - Maybe worth scripting in some case statements to check if there is a valid array with IsArray and then revert to varaible analysis if there is no array..Looks like the _AdFunctions.au3 has limitations in this function for this scenario .....Thanks for your hard work resolving this for me...Much appreciatedto you both (water and cherdeg)
bourny Posted November 28, 2008 Author Posted November 28, 2008 Water....Could I ask one more thing...How do I now get the original script you had to work with a non array variable as we have now got to ... I can now get the DC list after the troubleshooting but need to still do the original get last log on time bit - I have been trying to splice the following post with the latest non array script but failing miserably.post 16Thanks
water Posted November 28, 2008 Posted November 28, 2008 I would update the adfunctions.au3.As this is no part of the autoit package it won't be overwritten when you install the newest Autoit version.Therefore you could change line 1093 in adfunctions.au3 from$DCList[$DCList[0]] = $temparray[0]Then my version from this post should work fine for you as well.I will post our findings to the adfunctions thread. Maybe the author updates his UDF. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
bourny Posted November 28, 2008 Author Posted November 28, 2008 I would update the adfunctions.au3. As this is no part of the autoit package it won't be overwritten when you install the newest Autoit version. Therefore you could change line 1093 in adfunctions.au3 from$DCList[$DCList[0]] = $temparray[0] Then my version from this post should work fine for you as well. I will post our findings to the adfunctions thread. Maybe the author updates his UDF. Thanks again - Much easier than what I was trying to do. Will be a V.good idea for the adfunctions to incorperate this. I wonder if there are any other parts of the AdFunctions that will fail the same way - Cannot understand the reason why this happens but then again I havent used much object scripting .... Thanks
bourny Posted November 28, 2008 Author Posted November 28, 2008 Have started getting results thru - I am now able to get last logged on time after changing the file ... out of interest it does not really work on computers.... I have managed to get 2 last logged on times from loads of machines I have tried - mainly returns 0. The user accounts seem ok but computer accounts V. difficult to get the dates for ....
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now