Jump to content

Recommended Posts

Posted

I have a script to install Macromedia Studio on our machines and I have a group in Active Directory called "Studio8_Stations". I would like to be able for the script to check to see if it is a member of that group before it runs the installer script.

Posted (edited)

Try this:

#include "AD.au3"

Global $aMembers[1], $computer = "Computer10", $group = "Studio8_Stations", $found = False, $i

; 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)


; Get a sorted list of members for the first group the currently logged on user is a member of
$aMembers = _AD_GetGroupMembers($group)

If @error > 0 Then
    MsgBox(64, "Active Directory Functions - Example 1", "The group '" & $group & "' has no members")
Else
    For $i = 1 To $aMembers[0]
        If StringInStr($aMembers[$i], "CN=" & $computer & ",") Then
            MsgBox(64, "Information", $computer & " is a member of " & $group)
            $found = True
            ExitLoop
        EndIf
    Next
    If Not $found Then MsgBox(16, "Information", $computer & " is NOT a member of " & $group)
EndIf


; Close Connection to the Active Directory
_AD_Close()

You need made by water!

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)

Or even easier and faster:

#include <AD.au3>
Global $iResult, $sGroup = "Studio8_Stations"
; Open Connection to the Active Directory
_AD_Open()
If @error Then Exit MsgBox(16, "Active Directory", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended)
; Check if the computer is an immediate member of the group
If _AD_IsMemberOf($sGroup, @ComputerName & "$") = 1 Then
    ; Computer is member of the group - do whatever you need to do
EndIf
; 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 (edited)

Hi.

"Run Script if Computer is a member of group in AD" was the question?

So it's (maybe)

If _AD_IsMemberOf($sGroup, @computername) = 1

This is a question, as I'm not sure, *IF* the AD computer account name will always match the local @computername...

Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Posted

If you pass the computername as SamAccountName you have to append a dollar sign e.g. @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

 

  • 2 months later...
Posted

Water - Are you sure this is working? I can never get your script in Post 21 to find the computer in the group even though I know it is. Thanks for any help you can provide.

Posted

Yes, I am.

I just checked it again and it works.

Can you post the code you use?

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

 

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
  • Recently Browsing   0 members

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