Jump to content

Active Directory UDF - Help & Support (III)


water
 Share

Recommended Posts

Good MOrning - ok this is interesting

 

So continuing from yesterday - I added a AD_CreateComputer in an OU and run the code and added MsgBox(@error...) after create computer

 

I get a  1 in the message box

 

However when I search for the computer name in AD - it's not there

 

Any thoughts boss ?

 

Keep in mind all I have is

 

AD Open

AD Create COmputer

MessageBox

AD Close

Edited by OrangeCoder
Link to comment
Share on other sites

Did you have a look at the UDF? All return values and error codes are described in the header of the respective function.

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

 

Link to comment
Share on other sites

I  believe I did - for AD Create Computer if you get 1 its success

 

so it telling me success - but the computer not being successfully created in AD - even though AD Open ran successfully is what I am confused about

I am sorry if many of these questions seems obvious - I am trying to follow along and not be one of those - whining , it's not working folks. If it's coming across that way - it's not meant to be 

 

Link to comment
Share on other sites

So you learned something new today ;)
There is a big difference between "return value" and "error 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

 

Link to comment
Share on other sites

yes sir lesson learned - thank you Jedi Master Water

Different question though

So my AD Create computer works beautifully - CHECK

However if I comment out the AD CreateComputer and use the sample 

 

AD Join - code with the flag of 1. 

I get Computer Account for (PC Name) does not exist on the domain

If I uncomment out the AD Create COmputer

and re-run it I get - Computer (PC Name) is already a member of the domain

gonna slam my head against the desk as to why I can't get a 1 returned from the AD Join domain lol

Link to comment
Share on other sites

The sample code does not set parameter $iFlag=2 so it defaults to $iFlag=1 which means: "Joins a computer to a domain. Computer account must already exist in the domain (Default)".
So I suggest you set parameter $iFlag=2 if the computer does not exist on the domain or call _AD_CreateComputer in advance.

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

 

Link to comment
Share on other sites

When I run AD Join with the flag  of 2. I get the message telling it's it's already a member of the domain

 

When it's not a member - cause it's not in the OU. 

If I look on the system itself to see if it's set the workgroup or domain . It's still part of the workgroup

 

If I run AD Create computer in advance - then the computer does get created in the designated  OU but the computer is still a member of the WORKGROUP

Hopefully that makes sense - I think I communicated that correctly

Link to comment
Share on other sites

5 minutes ago, OrangeCoder said:

When I run AD Join with the flag  of 2. I get the message telling it's it's already a member of the domain
When it's not a member - cause it's not in the OU. 

When calling _ADJoinDomain without setting parameter $sOU the computer gets created in the Computer container.
A computer has to be unique in the whole AD tree. So you should not only check your OU but use the code I previously posted to check the whole tree for the computer using _AD_ObjectExists.

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

 

Link to comment
Share on other sites

I am learning to be more specific - sorry Water.

 

I will run the script to see if the object exists

However I didn't state that  when I called AD Join - I did specify the OU. I used the same OU I specified when I tested and confirmed AD CreateCOmputer (which was commented out once when trying to get just AD JoinDomain working)

Edited by OrangeCoder
Link to comment
Share on other sites

#RequireAdmin
#include <AD.au3>
_AD_ErrorNotify(2)
_AD_Open(VERIFIED THAT ALL PARAMETERS HERE DO WORK")
MsgBox(0,"",_AD_ObjectExists("Your Computername" & "$"))
;_AD_CreateComputer("VERIFIED THAT ALL PARAMETERS HERE ALSO WORK CAUSE WHEN UNCOMMENTED - COmputer is created in designated OU")
Global $iValue = _AD_JoinDomain(@ComputerName,"","","SAME OU USED IN AD_CREATECOMPUTER,2,'TestComputer4')
If $iValue = 1 Then
   MsgBox(64, "Active Directory Functions - Example 1", "Computer '" & @ComputerName & "' successfully joined. Please reboot the computer")
ElseIf @error = 1 Then
    MsgBox(64, "Active Directory Functions - Example 1", "Computer account for '" & @ComputerName & "' does not exist in the domain")
ElseIf @error = 3 Then
    MsgBox(64, "Active Directory Functions - Example 1", "WMI object could not be created. @extended=" & @extended)
ElseIf @error = 4 Then
    MsgBox(64, "Active Directory Functions - Example 1", "Computer '" & @ComputerName & "' is already a member of the domain")
ElseIf @error = 5 Then
    MsgBox(64, "Active Directory Functions - Example 1", "Joining computer '" & @ComputerName & "' to the domain was not successful. @extended=" & @extended)
Else
    MsgBox(64, "Active Directory Functions - Example 1", "Return code '" & @error & "' from Active Directory")
EndIf
MsgBox(0,"Error?",@error)
_AD_Close()

When I run the above

 

I get a 0 in the first message box

Then it telling me the computer is already a member of the domain

Then another messagebox with a 0

I refresh AD and look in the OU and the system isn't there

If I am understanding this correctly - The object doesn't exist in the AD correct ?

Edited by OrangeCoder
Link to comment
Share on other sites

If the "heck you don't know what you do" then playing with AD is far too complex ;)

So the first step would be: Define exactly what you want to do! Means:

  • In which OU should the computer be created?
  • Should the computer be created in the AD when joining or by explicitely calling _AD_CreateComputer?

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

 

Link to comment
Share on other sites

Thanks Water 

 

-I want computers created in an OU in AD thats called Testing

-I want the computer to be created when I call AD Join. 

NOTE: Just for testing to make sure I can create computers in that OU- i wrote the AD_Create to see if computers get created in the Testing OU. When I call AD_CreateComputer the computer does in fact get created in OU called Testing

When I use AD_Join the computer does not get created  in the Testing OU

Edited by OrangeCoder
Link to comment
Share on other sites

Could you please fill in the required data (lines marked with "<== Change") into this script and run it?
If it doesn't give the expected results then please replace all sensitive information (company name, Server name etc.) with xxx but please leave the format intact.
Means replace "DC=Microsoft" with "DC=xxxx".

#include <AD.au3>
_AD_Open("... Your parameters go here ...") ; <== Change
If @error Then Exit MsgBox(0, "Error", "_AD_Open: @error = " & @error & ", @extended = " & @extended) 
_AD_JoinDomain(@ComputerName, "", "", "... OU where to join the computer ...", 2) ; <== Change
If @error Then 
    Exit MsgBox(0, "Error", "_AD_JoinDomain: @error = " & @error & ", @extended = " & @extended)
Else
    MsgBox(0, "Success", "_AD_JoinDomain: @error = " & @error & ", @extended = " & @extended)
EndIf 
_AD_Close()
Exit

 

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

 

Link to comment
Share on other sites

Hey water so when I ran this I got a 

_AD_JoinDomain: @error=4, @extended = 0

#RequireAdmin
#include <AD.au3>
_AD_Open("xxxx\xxxx.xxxx", "xxxxxxx", "DC=xxxx,DC=xxxxxx,DC=xxx,DC=xx,DC=xx","xx-xx-1.xxxx.xxxxxx.xxx.xx.xx","CN=Configuration,DC=xxxx,DC=xxxxxx,DCxxx,DC=xx,DC=xx")
If @error Then Exit MsgBox(0, "Error", "_AD_Open: @error = " & @error & ", @extended = " & @extended)
_AD_JoinDomain(@ComputerName,"","","OU=TESTING,DC=xxxx,DC=xxxxxxx,DC=xxx,DC=xx,DC=xx,2)
If @error Then
    Exit MsgBox(0, "Error", "_AD_JoinDomain: @error = " & @error & ", @extended = " & @extended)
Else
    MsgBox(0, "Success", "_AD_JoinDomain: @error = " & @error & ", @extended = " & @extended)
EndIf
_AD_Close()
Exit
 

Link to comment
Share on other sites

This means the computer is already a member of the domain.
Is this true?

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

 

Link to comment
Share on other sites

yesterday I had manually joined the computer to the domain for testing something else unrelated

This morning before I tested the script you gave me - I unjoined it and made sure I deleted the computer from the domain and rebooted the system

I am 100% certain it's not a member of the domain

Good Morning Water

also - thank you for always being helpful and responding so freaking quickly - it's rather comforting lol 

Edited by OrangeCoder
Link to comment
Share on other sites

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
 Share

×
×
  • Create New...