Jump to content

_AD_AddUserToGroup UDF error


Recommended Posts

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

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>

Link to post
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

Link to post
Share on other sites

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

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 2022-02-19 - Version 1.6.1.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 (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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 2022-02-19 - Version 1.6.1.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 (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

    No registered users viewing this page.

×
×
  • Create New...