Jump to content

Recommended Posts

Posted

thanks for that bit of info, it was definately pointing in the right direction. i was able to paste a piece of sample code into an Excel macros and to my surprise - it worked for the most part. i have a few things to work out like i need to connect to z: intead of the local server but that has been a huge help.

maybe i can work that into the AD UDF

thanks

Posted

According to this article you should be able to read/write TS properties.

I think it should be possible using _AD_GetObjectAttribute and _AD_ModifyAttribute.

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

 

Posted

I have a script which I am trying to get the last logon of all machines in all OU's in my AD structure. The script terminates with an error on the 3rd OU. I am not sure why. Can you see any problems in this script? The first 2 OU's cycle through the machines fine.

Thanks.

#include <AD.au3>
_AD_Open()
Global $aOUs = _AD_GetAllOUs()
If Not FileExists ("C:\Temp") Then
DirCreate("C:\Temp")
EndIf
For $a = 1 To $aOUs[0][0]
$aObj = _AD_GetObjectsInOU($aOUs[$a][1],"(objectclass=computer)")
;MsgBox(0,"OU",$aObj[0] & @CR & $aOUs[$a][1])
For $b = 1 To $aObj[0]
  ;MsgBox(0,"Computer",$aObj[$b] & @CR & $aOUs[$a][1])
  $aProp = _AD_GetObjectProperties($aObj[$b],"lastLogon")
  MsgBox(0,"Date",$aObj[$b] & "=" & $aProp[1][1])
Next
Next
_AD_Close()

Error:

D:\Backup\AutoIT Script\Active Directory\AD Stale Computer Search.au3 (13) : ==> Subscript used with non-Array variable.:

For $b = 1 To $aObj[0]

For $b = 1 To $aObj^ ERROR

Posted

What does _AD_GetObjectsInOU return if there's nothing in the OU?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

_AD_GetObjectsInOU returns "" if there is no data to return and sets @error. Try this:

#include <AD.au3>
_AD_Open()
Global $aOUs = _AD_GetAllOUs()
If Not FileExists("C:Temp") Then
    DirCreate("C:Temp")
EndIf
For $a = 1 To $aOUs[0][0]
    $aObj = _AD_GetObjectsInOU($aOUs[$a][1], "(objectclass=computer)")
    If @error = 0 Then
        For $b = 1 To $aObj[0]
            $aProp = _AD_GetObjectProperties($aObj[$b], "lastLogon")
            MsgBox(0, "Date", $aObj[$b] & "=" & $aProp[1][1])
        Next
    EndIf
Next
_AD_Close()

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

 

Posted

OK, I jumped the gun there. So that code worked up until it got to the 9th machine in the OU (there are 79), but for some receiving at that 9th machine I am receiving this error message.

D:BackupAutoIT ScriptActive DirectoryAD Stale Computer Search.au3 (19) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

ConsoleWrite($aObj[$b] & "=" & $aProp[1][1] & @CR)

ConsoleWrite($aObj[$b] & "=" & ^ ERROR

Why would it throw an error in the middle of loop?

Posted

How does the code you run now look like? There is no ConsoleWrite in the code you posted above.

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

 

Posted

Sorry I modified it a little, so I could see where it was breaking a little better.

#include <AD.au3>
_AD_Open()
Global $aOUs = _AD_GetAllOUs()
If Not FileExists ("C:\Temp") Then
DirCreate("C:\Temp")
EndIf
For $a = 1 To $aOUs[0][0]
;MsgBox(0,"",$aOUs[$a][1])
$aObj = _AD_GetObjectsInOU($aOUs[$a][1],"(objectclass=computer)")
;MsgBox(0,"OU",$aObj[0] & @CR & $aOUs[$a][1])
If @error = 0 Then
  ;MsgBox(0,"OU",$aObj[0] & @CR & $aOUs[$a][1])
  For $b = 1 To $aObj[0]
   ;MsgBox(0,"Computer",$aObj[$b] & @CR & $aOUs[$a][1])
   $aProp = _AD_GetObjectProperties($aObj[$b],"lastLogon")
   ConsoleWrite($aObj[$b] & "=" & $aProp[1][1] & @CR)
  Next
EndIf
Next
_AD_Close()
Posted

I'm sure _AD_GetObjectProperties returns an error. Insert

ConsoleWrite(@error & @CRLF)
after _AD_GetObjectProperties and you will see what goes wrong. In case of an error the function doesn't return an array but a string.

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

 

Posted

So this is the code I used.

#include <AD.au3>
_AD_Open()
Global $aOUs = _AD_GetAllOUs()
If Not FileExists ("C:Temp") Then
 DirCreate("C:Temp")
EndIf
For $a = 1 To $aOUs[0][0]
 ;MsgBox(0,"",$aOUs[$a][1])
 $aObj = _AD_GetObjectsInOU($aOUs[$a][1],"(objectclass=computer)")
 MsgBox(0,"OU",$aObj[0] & @CR & $aOUs[$a][1])
 If @error = 0 Then
  ;MsgBox(0,"OU",$aObj[0] & @CR & $aOUs[$a][1])
  For $b = 1 To $aObj[0]
   MsgBox(0,"Computer",$aObj[$b] & @CR & $aOUs[$a][1])
   $aProp = _AD_GetObjectProperties($aObj[$b],"lastLogon")
   ConsoleWrite(@error & @CRLF)
   ConsoleWrite($aObj[$b] & "=" & $aProp[1][1] & @CR)
  Next
 EndIf
Next
_AD_Close()

This is what I received back.

BACKUPSTORE$=2012/04/30 16:30:03

0

CAD-LICSRV1$=2012/05/12 01:33:28

0

D:BackupAutoIT ScriptActive DirectoryAD Stale Computer Search.au3 (20) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

ConsoleWrite($aObj[$b] & "=" & $aProp[1][1] & @CR)

ConsoleWrite($aObj[$b] & "=" & ^ ERROR

I can't get anything from that. Do you see anything that could be causing an issue?

Thanks.

Posted (edited)

In the remarks section of the function you find: "No error is returned if there are properties in $sAD_Properties that are not available for the selected object".

So I would check for the returned data like this:

If IsArray($aProp) and $aProp[0][0] > 0 Then ConsoleWrite($aObj[$b] & "=" & $aProp[1][1] & @CR)
Edited by water

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

 

Posted

Hi Water!,

How are you? i m fine! now i currently working on a task which has to retrive the data from AD. Let me explain my input below.

When i execute the tool, it should collect all the country names. from my AD structure.

For example: in my AD i will be have hirarchies like, workstation->GD2000->(Europe,US,Asiapacific,etc.) under this regions i will having lot of country names. As a first step it should collect me the regions details.

After collecting that region details if i select any region it should explore all the country name which comes under that region.

Then the next step if i select any country name it should explore the city name. From that city name i should be able to select the machine models from the AD and it's name.

is that possible to do with our AD function? Please help me on this Water! i know this is a big task for me, but if you help i can complete it so easily!

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Posted

HI Syed,

glad to hear you're fine. I'm doing well too.

What kind of objects do you use to create the hierarchy? OU's, CN's, groups ...?

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

 

Posted

You then could give the example script a try.

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

 

Posted

ok! Let me try that option and i'll get back to you on this....

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Posted

Hi Water,

That shows perfect. my quick question now i have been listed with all the OU site. and i have selected the OU. is there a way to find the user details based on the machine model?

For example, if i have HPXXXX model in one OU arround 30 users and HPYYYY model we have 300 users. is there a way to find the user list based on the model?

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...