water Posted February 25, 2013 Author Posted February 25, 2013 $test = _AD_IsMemberOf("Computers", "pcsetup8", TRUE) MsgBox(0, "", "@error: " & @error & ", @extended: " & @extended) 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
blumi Posted February 25, 2013 Posted February 25, 2013 $test = _AD_IsMemberOf("Computers", "pcsetup8", TRUE) MsgBox(0, "", "@error: " & @error & ", @extended: " & @extended) @error: 1 @extended: 0
water Posted February 25, 2013 Author Posted February 25, 2013 (edited) I assume that the group you want to check is the Primary Group.So the script should look like:#include <AD.au3> ; Open Connection to the Active Directory _AD_Open() If @error Then Exit MsgBox(16, "Active Directory Example Skript", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended) $sResult = _AD_GetUserPrimaryGroup("pcsetup8$") ; <== Note the dollar sign at the end of the computername MsgBox(0, "", "$sResult: " & $sResult & @CRLF & "@error: " & @error & @CRLF & "@extended: " & @extended) ; Close Connection to the Active Directory _AD_Close() Edited February 25, 2013 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
blumi Posted February 25, 2013 Posted February 25, 2013 I assume that the group you want to check is the Primary Group.So the script should look like:#include <AD.au3> ; Open Connection to the Active Directory _AD_Open() If @error Then Exit MsgBox(16, "Active Directory Example Skript", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended) $sResult = _AD_GetUserPrimaryGroup("pcsetup8$") ; <== Note the dollar sign at the end of the computername MsgBox(0, "", "$sResult: " & $sResult & @CRLF & "@error: " & @error & @CRLF & "@extended: " & @extended) ; Close Connection to the Active Directory _AD_Close() Thought this function is only for users, I am looking for a computer(name). The computer pcsetup8 exists in the group computers on the domain controller When I run the script result is CN=Domänencomputer, CN=Users,DC...
water Posted February 25, 2013 Author Posted February 25, 2013 Returncode 1 you got with _AD_IsMemberOf tell you that the group doesn't exist. That's why I thought it was the Primary Group. If a user/computer is a member of a group then the name of the user/computer account is stored with the group. A Primary group works the other way round so the ID of teh Primary group is stored with every user/computer. This is to enhance performance because Priamry Groups can have thousands of members. Is "Computers" the SamAccountName for "CN=Domänencomputer,CN=Users,DC..."? 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
CoolDude69 Posted February 28, 2013 Posted February 28, 2013 (edited) I would need some guidance please; at work one user can have more then one computer assigned to him, what I need is to get the list of all the "managedObjects" and only display the units that have "Primary" in the description. I tried with an example that Water supplied before but I don't get what I need, I might still be sleeping or not seeing the issue. The example below gives me all the computers with the description "Primary" but I need to filter it by user. I might be doing it in the wrong order. _AD_Open() $aGroups = _AD_GetObjectsInOU("", "(&(objectclass=computer)(description=*Primary*))", 2, "sAMAccountName,description") _ArrayDisplay($aGroups) For $i = 1 To 5; only for testing ConsoleWrite("Computer: " & $aGroups[$i][0] & ", Description: " & $aGroups[$i][1] & @LF) $aMembers = _AD_GetGroupMembers($aGroups[$i][0]) For $j = 1 To $aMembers[0] $sDescription = _AD_GetObjectAttribute($aMembers[$j], "description") ConsoleWrite(" User: " & $aMembers[$j] & ", Description: " & $sDescription & @LF) Next Next _AD_CLose() Edited February 28, 2013 by CoolDude69
blumi Posted February 28, 2013 Posted February 28, 2013 Is "Computers" the SamAccountName for "CN=Domänencomputer,CN=Users,DC..."?No, "Computers" is a standard CN on the windows domain controller. If a pc is integrated into the domain it will appear in this CN.distinguishedName CN=Computers,DC=emi,DC=fhg,DC=deWe build an OU which is called "Workstations" into this group some pcs are moved manually.distinguishedName OU=Workstations,DC=emi,DC=fhg,DC=deWhat I want to do with your funcions is just check if a computername is member of the OU workstations.
water Posted February 28, 2013 Author Posted February 28, 2013 (edited) CoolDude69, I think you only need a single query: $aComputers = _AD_GetObjectsInOU("", "(&(objectclass=computer)(description=*Primary*)(managedBy=*))", 2, "sAMAccountName,description,managedBy") Will return a list of computers where the description contains "*Primary*" and which have a manager assigned. Unfortunately I can't test. So please give it a try and post the result. Edited February 28, 2013 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
water Posted February 28, 2013 Author Posted February 28, 2013 blumi, add a dollar sign to the computer name (samaccountname): $test = _AD_IsMemberOf("Computers", @ComputerName & "$") 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
CoolDude69 Posted February 28, 2013 Posted February 28, 2013 CoolDude69, I think you only need a single query: $aComputers = _AD_GetObjectsInOU("", "(&(objectclass=computer)(description=*Primary*)(managedBy=*))", 2, "sAMAccountName,description,managedBy") Will return a list of computers where the description contains "*Primary*" and which have a manager assigned. Unfortunately I can't test. So please give it a try and post the result. Thank you Water, I had this query but I don't get what I need, I need to look up each user and get only the computer(s) that have Primary in the description.
water Posted February 28, 2013 Author Posted February 28, 2013 I had this query but I don't get what I need ...What does this mean? You get to many computers, not all computers, invalid data in the returned array ...? 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
CoolDude69 Posted February 28, 2013 Posted February 28, 2013 (edited) What does this mean? You get to many computers, not all computers, invalid data in the returned array ...?I get all the computers that have Primary as a description (I don't want all of them). I run a query that pulls users from AD (query done by department / location) from that list of users I need to get only the computers that are assigned and have primary in the description. Edited February 28, 2013 by CoolDude69
CoolDude69 Posted February 28, 2013 Posted February 28, 2013 water here's a list that I have for one user, from all these systems I only want the ones that have Primary in the description. This is why I was using 2 queries, one to get the user and then look up all the units assigned to him and only pull Primary systems. [37]|managedObjects|CN=HALAPP01,OU=Servers,OU=Location,OU=Department,OU=Domain,DC=Domaincorp,DC=Domain,DC=com [38]|managedObjects|CN=MHPSODA,OU=Servers,OU=Location,OU=Department,OU=Domain,DC=Domaincorp,DC=Domain,DC=com [39]|managedObjects|CN=HALAPP02,OU=Servers,OU=Location,OU=Department,OU=Domain,DC=Domaincorp,DC=Domain,DC=com [40]|managedObjects|CN=HALL0127,OU=Laptops,OU=Location,OU=Department,OU=Domain,DC=Domaincorp,DC=Domain,DC=com [41]|managedObjects|CN=HALPC0030,OU=Computers,OU=Location,OU=Department,OU=Domain,DC=Domaincorp,DC=Domain,DC=com [42]|managedObjects|CN=HALL0127-XPVM,OU=Laptops,OU=Location,OU=Department,OU=Domain,DC=Domaincorp,DC=Domain,DC=com [43]|managedObjects|CN=HALPC0019,OU=Computers,OU=Location,OU=Department,OU=Domain,DC=Domaincorp,DC=Domain,DC=com [44]|managedObjects|CN=HALBCK01,OU=Servers,OU=Location,OU=Department,OU=Domain,DC=Domaincorp,DC=Domain,DC=com [45]|managedObjects|CN=HALL0083,OU=Laptops,OU=Location,OU=Department,OU=Domain,DC=Domaincorp,DC=Domain,DC=com [46]|managedObjects|CN=HALAPP03,OU=Servers,OU=Location,OU=Department,OU=Domain,DC=Domaincorp,DC=Domain,DC=com [47]|managedObjects|CN=HALFIL01,OU=Servers,OU=Location,OU=Department,OU=Domain,DC=Domaincorp,DC=Domain,DC=com
water Posted February 28, 2013 Author Posted February 28, 2013 How many computers do we talk about (total)? 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
CoolDude69 Posted February 28, 2013 Posted February 28, 2013 How many computers do we talk about (total)?The array comes up with 637 systems.
water Posted February 28, 2013 Author Posted February 28, 2013 If you use this query$aComputers = _AD_GetObjectsInOU("", "(&(objectclass=computer)(description=*Primary*)(managedBy=*))", 2, "sAMAccountName,description,managedBy")you get the manager of this computer in the 3rd column. Compare this with the array of users and drop all computers which aren't managed by on of the users. 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
CoolDude69 Posted February 28, 2013 Posted February 28, 2013 If you use this query$aComputers = _AD_GetObjectsInOU("", "(&(objectclass=computer)(description=*Primary*)(managedBy=*))", 2, "sAMAccountName,description,managedBy")you get the manager of this computer in the 3rd column. Compare this with the array of users and drop all computers which aren't managed by on of the users. Once again thank you. You got me going in the right direction; here's my working script: #include Global $aUser = @UserName _AD_Open() $AD_User = _AD_GetObjectAttribute($aUser, "managedObjects") For $i = 1 To UBound($AD_User) - 1 $Asset = StringRegExpReplace(StringReplace($AD_User[$i], 'CN=', ''), "(,.*)", "") $Primary = _AD_GetObjectsInOU("", "(&(objectclass=computer)(sAMAccountName=" & $Asset & "*)(description=*Primary*))", 2, "sAMAccountName,description") For $x = 1 To UBound($Primary) - 1 ConsoleWrite($Asset) Next Next _AD_CLose() Cheers
water Posted February 28, 2013 Author Posted February 28, 2013 Looks good. If you need to enhance performance it should be possible. 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
CoolDude69 Posted February 28, 2013 Posted February 28, 2013 Looks good. If you need to enhance performance it should be possible.How?
water Posted February 28, 2013 Author Posted February 28, 2013 By reducing the number of calls to _AD_* functions. Get a list of all computers with description="*Primary*" with the name of the manager. Then compare this list to the list of users. Can't test at the moment but will provide an example tomorrow. 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
Recommended Posts