473,385 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Creating Groups in AD

I am trying to write code that creates groups in AD using the DirectoryEntry
object in .NET. (I used to be able to do this easily using VBScript...)

Anyways, the following code throws a VEY generic (and unhelpful) error
message. The most obvious reason is that I am not setting some required
property but I have no clue which property that may be. I cannot seem to
find any samples on how to manipulate groups (only on how to work with
users).

entry = New DirectoryEntry("LDAP://ou=MyGroups,dc=mydomain,dc=com")
group = entry.Children.Add("cn=test", "Group")
group.CommitChanges()

The exception thrown is "A constraint violation occurred".

Thanks,
Jason
Nov 22 '05 #1
5 4024
Search for active directory and vb.net on google and you will find few
articles that will help.

"Jason" wrote:
I am trying to write code that creates groups in AD using the DirectoryEntry
object in .NET. (I used to be able to do this easily using VBScript...)

Anyways, the following code throws a VEY generic (and unhelpful) error
message. The most obvious reason is that I am not setting some required
property but I have no clue which property that may be. I cannot seem to
find any samples on how to manipulate groups (only on how to work with
users).

entry = New DirectoryEntry("LDAP://ou=MyGroups,dc=mydomain,dc=com")
group = entry.Children.Add("cn=test", "Group")
group.CommitChanges()

The exception thrown is "A constraint violation occurred".

Thanks,
Jason

Nov 22 '05 #2
I have already tried doing google searches but did so again with your
suggested criteria. No help. Have yet to find a single article on how to
create a group or what the minimum required fields are when creating said
group.

- Jason

"D_longhorn" <Dl*******@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
Search for active directory and vb.net on google and you will find few
articles that will help.

"Jason" wrote:
I am trying to write code that creates groups in AD using the
DirectoryEntry
object in .NET. (I used to be able to do this easily using VBScript...)

Anyways, the following code throws a VEY generic (and unhelpful) error
message. The most obvious reason is that I am not setting some required
property but I have no clue which property that may be. I cannot seem to
find any samples on how to manipulate groups (only on how to work with
users).

entry = New DirectoryEntry("LDAP://ou=MyGroups,dc=mydomain,dc=com")
group = entry.Children.Add("cn=test", "Group")
group.CommitChanges()

The exception thrown is "A constraint violation occurred".

Thanks,
Jason

Nov 22 '05 #3
This should work unless there is a privilege constraint, the user
credentials used to bind are those of the current user.
Therefore I suggest you execute the same code using explicit credentials of
a domain admin.

Willy.

"Jason" <Ja*******@hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
I am trying to write code that creates groups in AD using the
DirectoryEntry object in .NET. (I used to be able to do this easily using
VBScript...)

Anyways, the following code throws a VEY generic (and unhelpful) error
message. The most obvious reason is that I am not setting some required
property but I have no clue which property that may be. I cannot seem to
find any samples on how to manipulate groups (only on how to work with
users).

entry = New DirectoryEntry("LDAP://ou=MyGroups,dc=mydomain,dc=com")
group = entry.Children.Add("cn=test", "Group")
group.CommitChanges()

The exception thrown is "A constraint violation occurred".

Thanks,
Jason

Nov 22 '05 #4
>I am trying to write code that creates groups in AD using the DirectoryEntry
object in .NET. (I used to be able to do this easily using VBScript...)

entry = New DirectoryEntry("LDAP://ou=MyGroups,dc=mydomain,dc=com")
group = entry.Children.Add("cn=test", "Group")
group.CommitChanges()

The exception thrown is "A constraint violation occurred".


You also need to set at least the mandatory attributes, which includes
"sAMAccountName" !

entry = New DirectoryEntry("LDAP://ou=MyGroups,dc=mydomain,dc=com")
group = entry.Children.Add("cn=test", "Group")
group.Properties["sAMAccountName"].Value = "test";
group.CommitChanges()

Also, be aware that the SAM account name needs to be UNIQUE in your
domain! If it's not unique, the creation will fail.

Marc

================================================== ==============
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
Nov 22 '05 #5
Thanks Marc. That was it.

- Jason

"Marc Scheuner [MVP ADSI]" <m.********@inova.SPAMBEGONE.ch> wrote in message
news:2a********************************@4ax.com...
I am trying to write code that creates groups in AD using the
DirectoryEntry
object in .NET. (I used to be able to do this easily using VBScript...)

entry = New DirectoryEntry("LDAP://ou=MyGroups,dc=mydomain,dc=com")
group = entry.Children.Add("cn=test", "Group")
group.CommitChanges()

The exception thrown is "A constraint violation occurred".


You also need to set at least the mandatory attributes, which includes
"sAMAccountName" !

entry = New DirectoryEntry("LDAP://ou=MyGroups,dc=mydomain,dc=com")
group = entry.Children.Add("cn=test", "Group")
group.Properties["sAMAccountName"].Value = "test";
group.CommitChanges()

Also, be aware that the SAM account name needs to be UNIQUE in your
domain! If it's not unique, the creation will fail.

Marc

================================================== ==============
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch

Nov 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: EJ | last post by:
Does anyone know if there is a class for creating doc files? I have seen ones for pdf and excel spreadsheets. Thanks in advance.
1
by: bob4roxio | last post by:
Is there any better quality method for creating resized images? I'm using imagecreatetruecolor and imagecopyresampled and making sure my imagejpeg quality is set at 100 but the client I'm writing...
3
by: Bryan Meyer | last post by:
Hello Everyone: I have a PHP script that attempts to create a temporary file to be used during processing. The script is owned by my username (bryanrme) on the server. When the script attempts...
5
by: Jason | last post by:
I am trying to write code that creates groups in AD using the DirectoryEntry object in .NET. (I used to be able to do this easily using VBScript...) Anyways, the following code throws a VEY...
1
by: Rosy | last post by:
I have a need to set permission levels to a database I have created. I need three to four groups that will have different access to different parts of the database. Each group will have between 3...
0
by: Sergej Pioch | last post by:
Hello everybody, im trying hard to automate some tasks in a huge windows environment. This lend me to bigger problems while trying to create new global security groups within active directory....
1
by: M K | last post by:
Can I create code so that when my users create a username in an Intranet form (Using Integrated Windows security) that user gets added to AD under a certain group? Where can I get info on this?
6
by: Jeff | last post by:
Hi - I understand how to create a directory folder, but how can I programatically create a _shared_ directory folder and set its permissions?? (I'm using VB.NET.) Thanks for your help. -...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
1
by: Rako | last post by:
My problem is: I want to create an index to any of the available picture-groups. This index is a table of thumbs with a scrollbar. If you click on the thumb, you get the full picture displayed. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.