Sign in to follow this  
Followers 0
geriksen73

Problem with AD.au3 and _AD_DeleteObject

43 posts in this topic

Hi,

I just can't figure this out... I've been able to use _AD_CreateOU without any problem. But now when I want to select the OU from a list and delete it it won't??? Here my default code:

$iValue = _AD_DeleteObject($deleteOU, _AD_GetObjectClass($deleteOU))

The object is an OU, and everything looks good, but... it returns @error: -2147352567 and @extended: 0

Please help!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

An OU can only be deleted when it is empty. That means no objects or any other OUs should exist in the Ou to be deleted.

Details about the problem plus a solution can be found

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hi again,

The OU for test is EMPTY... so I really don't know what's wrong. Tried with DOMAIN\Username aswell for the _AD_Open()... I can use the _AD_Create_OU() just fine... Any clues???

Share this post


Link to post
Share on other sites

-2147352567 is 0x80020009 (hex) which means "Unexpected error" and could be everything.

Which version of the UDF do you use (this info can be found in the header of the AD.au3 file)?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hi again,

It's UDF Version ...: 1.2.0 and the AutoIT version are: 3.3.8.1. I've checked that I get the following values:

$iValue = _AD_DeleteObject($deleteOU, _AD_GetObjectClass($deleteOU)) where

$deleteOU returns: OU=Test-OU,DC=smi,DC=local

and

_AD_GetObjectClass($deleteOU) returns: organizationalUnit

I've also included the:

$aError = _AD_GetLastADSIError()

_ArrayDisplay($aError)

and this shows the following:

[0]|5

[1]|0

[2]|

[3]|LDAP Provider

[4]|

[5]|The operation completed successfully.

???

Share this post


Link to post
Share on other sites

With version 1.2.0 you can insert

$iAD_Debug = 2
before deleting the OU and you will receive the output of the COM error handler. That should help to solve the problem.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

OK, it says the following:

First dialog box:

Scriptline=685

Description=The directory property cannot be found in the cache.

Second dialog box:

Scriptline=2589

Description=An invalid directory pathname was passed

Hope this helps???

Share this post


Link to post
Share on other sites

Thanks. That makes debugging much easier.

The first message is triggered by function _AD_GetObjectAttribute and means that a property is queried that doesn't exist. _AD_GetObjectAttribute is called by _AD_DeleteObject.

The second message is triggered by function _AD_DeleteObject and means that the specified OU doesn't exist.

I'm not 100% sure at the moment but I think it's a bug in function _AD_DeleteObject.

I will have to investigate and post a reply as soon as possible.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Excellent! Then I'll just wait and see...

Share this post


Link to post
Share on other sites

Could you please test with this modified function?

Func _AD_DeleteObject($sAD_Object, $sAD_Class)

    If Not _AD_ObjectExists($sAD_Object) Then Return SetError(1, 0, 0)
    Local $sAD_CN
    If StringMid($sAD_Object, 3, 1) <> "=" Then $sAD_Object = _AD_SamAccountNameToFQDN($sAD_Object) ; sAMAccountName provided
    Local $oAD_Object = _AD_ObjGet("LDAP://" & $sAD_HostServer & "/" & $sAD_Object)
    Local $oAD_OU = _AD_ObjGet($oAD_Object.Parent) ; Get the object of the OU/CN where the object resides
    If $sAD_Class = "organizationalUnit" Then
        $sAD_CN = "OU=" & _AD_GetObjectAttribute($sAD_Object, "ou")
    Else    
        $sAD_CN = "CN=" & _AD_GetObjectAttribute($sAD_Object, "cn")
    EndIf
    $oAD_OU.Delete($sAD_Class, $sAD_CN)
    If @error <> 0 Then Return SetError(@error, 0, 0)
    Return 1

EndFunc   ;==>_AD_DeleteObject

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hi again,

I'm pleased to inform that this works!!!

Seems like your script maybe don't account for deleting in "root" like I tried to... This OU was created in the root that I tried to delete... So can I use this new Func on permanent basis or???

Also having problem getting this command to work:

Don't work:

RunWait(@ComSpec & ' /k powershell -ExecutionPolicy bypass -Command "& {Import-Module ActiveDirectory; Get-ADDomain -Identity ' & $AD_DNS_DomainName & '";}"' & ">" & $tFile5,"")

...and this work:

RunWait(@ComSpec & ' /c powershell -ExecutionPolicy bypass -Command "& {Import-Module ActiveDirectory; Get-ADDomainController;}"' & ">" & $tFile1,"", @SW_HIDE)

Can you help me here???

Share this post


Link to post
Share on other sites

Deleting an OU which was created in the root doesn't work with the modified version of the function, right?

What do you try to achieve with powershell? Maybe it's already included in the AD UDF.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

The modified version of the fuction works perfect! When I mean deleting i "root" I just mean that this OU is created in the domain root -> "smi.local" in my case... So If I open up AD Users and Computers on the DC, I see it created in the root level under my domain... Do you understand?

Regarding the Powershell command, I want to write the Get-ADDomain -Identity smi.local (my domain) info... From there I want to get the "NetBIOSName" value from it... Since I say you stated in another thread that this could be related to the _AD_Open() without Username convention like: DOMAINUsername... It's just for that and any other values I need extracted from it... ;)

Share this post


Link to post
Share on other sites

The modified version of the fuction works perfect! When I mean deleting i "root" I just mean that this OU is created in the domain root -> "smi.local" in my case... So If I open up AD Users and Computers on the DC, I see it created in the root level under my domain... Do you understand?

I just was not sure if the modified version works for OU's in the root as well. As it does the modified version of the function will be part of the next version. So you can safely replace _AD_DeleteObject in the UDF with the modified version.

The domain you are connected to can be obtained using macro @LogonDomain.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I knew that... The problem is this machine are still not a member in the domain, but I want to make some changes BEFORE I create and join it to the domain, so that's why I can't use the macro... Well, I'll find a way some how, and a million thanks for quick and excellent reply! Really appreciate it!!! ;)

Share this post


Link to post
Share on other sites

Glad to be of service ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Sorry for another issue here... But this is critical!

When I now try out my Join script, I get the following error:

Scriptline=2441

WinDescription=The security ID structure is invalid.

I'm not sure if this is related to the Create Computer og Join Domain Functions...

Please advise!

Share this post


Link to post
Share on other sites

Line 2441 is in function _AD_CreateComputer. We never had any problems with this function before.

What AD version do you use (2000, 2003, 2008)?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

We use 2008 R2 SP1...

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

This problem was described Unfortunately the OP never came back to tell if the link I posted solved the problem or not.

Could you please read the thread starting with the specified post and tell me if this fits your situation?

Here is another on the subject. The problem was caused by missing permissions.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0