Jump to content

Recommended Posts

Posted

$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

 

Posted (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 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

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...

Posted

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

 

Posted (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("", "(&amp;(objectclass=computer)(description=*Primary*))", 2, "sAMAccountName,description")
_ArrayDisplay($aGroups)
For $i = 1 To 5; only for testing
ConsoleWrite("Computer: " &amp; $aGroups[$i][0] &amp; ", Description: " &amp; $aGroups[$i][1] &amp; @LF)
$aMembers = _AD_GetGroupMembers($aGroups[$i][0])
For $j = 1 To $aMembers[0]
$sDescription = _AD_GetObjectAttribute($aMembers[$j], "description")
ConsoleWrite(" User: " &amp; $aMembers[$j] &amp; ", Description: " &amp; $sDescription &amp; @LF)
Next

Next
_AD_CLose()
Edited by CoolDude69
Posted

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=de

We build an OU which is called "Workstations" into this group some pcs are moved manually.

distinguishedName OU=Workstations,DC=emi,DC=fhg,DC=de

What I want to do with your funcions is just check if a computername is member of the OU workstations.

Posted (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 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

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

 

Posted

CoolDude69,

I think you only need a single query:

$aComputers = _AD_GetObjectsInOU("", "(&amp;(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.
Posted

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

 

Posted (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 by CoolDude69
Posted

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

Posted

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

 

Posted

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

 

Posted

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

Posted

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

 

Posted

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

 

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

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