Sign in to follow this  
Followers 0
Ben214

Proper syntax for _ADAddUserToGroup variables?

3 posts in this topic

I am trying to use the _ADAddUserToGroup function from the ADFunctions.au3 UDF however am having some trouble when tring to send this variable to it

$group = "cn=office, OU=company, OU=affiliate, DC=central, DC=network, DC=com"

I'm just trying to get the function to work before I add in actual variables and clean it up. Whenever I use it it gives me the error "There is no such object on the Server."

I have used the _NetAPI_GroupAddUser function and that does work beautifully, however I wanted to try the other function because I think I can get the group membership of a single user from the _ADGetUserGroups function into an array and then mirror a new user to have the same groups without having to manipulate the data.

Share this post


Link to post
Share on other sites



Not sure if you ever figured this out, but here's how I got it working.

_ADAddUserToGroup(_ADSamAccountNameToFQDN($sGroup), _ADSamAccountNameToFQDN($sUser))

It says to use the SamAccountName in the function comments, but it really needs the DN to both the group and user. It also says you don't need the leading CN= which is incorrect.

Just use it similar to how I've shown above in my example and you should be fine. Just be careful with some groups. I ran into a few special groups where the SamAccountName wasn't the same as the name or cn.

Share this post


Link to post
Share on other sites

Thanks Cyri. I searched a bit and got this module to work using _ADDNToSamAccountName and the _NetAPI_GroupAddUser function from elsewhere. It isn't pretty but it works. Looks like this:

for $loop = 1 to $counter
    $name = _ADDNToSamAccountName($array[$loop])
    _NetAPI_GroupAddUser($user, $name, "your.network.com")
Next

This acts as a copy/paste for one user and mirrors the groups onto a new user.

I'll keep my eyes open for the groups that have the different SamAccountName.

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