Sign in to follow this  
Followers 0
Ivo

_AD_AddUserToGroup UDF error

8 posts in this topic

Hi all

I am using the _AD_AddUserToGroup from ad.au3 to add users to an AD Group.

It work fine as long as I dont have users with an / in the FQDN.

If there is a "/" in the FQDN I got the error number -2147352567 from @error

#include <AD.au3>

_AD_Open()

;This doesn't work
_AD_AddUserToGroup("CN=SG-ALL-Employees,OU=Security Groups,OU=GROUPS,DC=OFFICE,DC=ORG","CN=Jan Jansen (ATF/G),OU=NL,OU=Users,DC=OFFICE,DC=org")

;This works fine
_AD_AddUserToGroup("CN=SG-ALL-Employees,OU=Security Groups,OU=GROUPS,DC=OFFICE,DC=ORG","CN=Klaas Vaak (BDF-R),OU=NL,OU=Users,DC=OFFICE,DC=org")


_AD_Close()

Any ideas?

Thanks in advance

Ivo


Ivo

Share this post


Link to post
Share on other sites



I cannot test this, so I don't know if it will work. It's worth a try.

$forwardslash = chr (47)
_AD_AddUserToGroup("CN=SG-ALL-Employees,OU=Security Groups,OU=GROUPS,DC=OFFICE,DC=ORG","CN=Jan Jansen (ATF" & $forwardslash & "G),OU=NL,OU=Users,DC=OFFICE,DC=org")

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You have to escape the slash. Use "\/" instead of "/".

Or use the internal function _AD_FixSpecialChars.

$sResult = _AD_FixSpecialChars($sString, <0 = escape, 1 = unescape>, "<list of characters to escaep/unescape>")
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

I tried this but it didn't work.

I cannot test this, so I don't know if it will work. It's worth a try.

$forwardslash = chr (47)
_AD_AddUserToGroup("CN=SG-ALL-Employees,OU=Security Groups,OU=GROUPS,DC=OFFICE,DC=ORG","CN=Jan Jansen (ATF" & $forwardslash & "G),OU=NL,OU=Users,DC=OFFICE,DC=org")


Ivo

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

You have to escape the slash. Use "\/" instead of "/".

Or use the internal function _AD_FixSpecialChars.

$sResult = _AD_FixSpecialChars($sString, <0 = escape, 1 = unescape>, "<list of characters to escaep/unescape>")

_AD_AddUserToGroup("CN=SG-ALL-Employees,OU=Security Groups,OU=GROUPS,DC=OFFICE,DC=ORG","CN=Jan Jansen (ATF\/G),OU=NL,OU=Users,DC=OFFICE,DC=org")

or

$sResult = _AD_FixSpecialChars("CN=Jan Jansen (ATF/G),OU=NL,OU=Users,DC=OFFICE,DC=org")

_AD_AddUserToGroup("CN=SG-ALL-Employees,OU=Security Groups,OU=GROUPS,DC=OFFICE,DC=ORG",$sResult)

Doesn't work.

It says that the user doesn't exis in the AD.

But it has something to do with the _AD_FixSpecialChars Func.

I got it to work with the following lines:

$SamID = _AD_FQDNToSamAccountName("CN=Jan Jansen (ATF/G),OU=NL,OU=Users,DC=OFFICE,DC=org")

_AD_AddUserToGroup("CN=SG-ALL-Employees,OU=Security Groups,OU=GROUPS,DC=OFFICE,DC=ORG",$SamID)

and those lines use the _AD_FixSpecialChars Function internally.

Thanks for you help.

Edited by Jos

Ivo

Share this post


Link to post
Share on other sites

I see. The problem was with the call to _AD_FixSpecialChars and using default parameters.

$sResult = _AD_FixSpecialChars("CN=Jan Jansen (ATF/G),OU=NL,OU=Users,DC=OFFICE,DC=org")
gets a result of
CN=Jan Jansen (ATF\/G)\,OU=NL\,OU=Users\,DC=OFFICE\,DC=org
which is incorrect because the commas are escaped as well.

The line

$sResult = _AD_FixSpecialChars("CN=Jan Jansen (ATF/G),OU=NL,OU=Users,DC=OFFICE,DC=org", 0, "/")
returns the correct result of
CN=Jan Jansen (ATF\/G),OU=NL,OU=Users,DC=OFFICE,DC=org

Do you think I should change _AD_FixSpecialChars into a "normal" function and insert extended documentation and examples?


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 function has helped me so I think it is a good idea to add it to the "normal" functions.

My script is ready now and implemented in our organisation.

Thanks again.


Ivo

Share this post


Link to post
Share on other sites

Thanks for your reply. Will be a part of the next version.


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