Connecting Tech Pros Worldwide Help | Site Map

Creating a User object in AD

Philip Carnstam
Guest
 
Posts: n/a
#1: Nov 16 '05
Hi,

Can someone lead me through creating a user object in AD.

I have tried creating one through LDAP and ADSI (WinNT://) but nothing
happens.

DirectoryEntry DE = new DirectoryObject("CN=users,DC=ADomain,DC=com");
DE.Children.Add("Philip", "user");
DE.CommitChanges();

This script does absolutely nothing. Why?


Thanks,
Philip




Willy Denoyette [MVP]
Guest
 
Posts: n/a
#2: Nov 16 '05

re: Creating a User object in AD


Your DirectoryObject should at least contain a correct LDAP ADsPath;
LDAP://HostName[:PortNumber][/DistinguishedName]

In your case
DirectoryEntry DE = new
DirectoryObject(LDAP://serverName/CN=users,DC=ADomain,DC=com);
Where serverName is the name of the AD server host or the domain name.

Willy.

"Philip Carnstam" <philip@carnstam.net> wrote in message
news:ehq2duQbEHA.3512@TK2MSFTNGP12.phx.gbl...[color=blue]
> Hi,
>
> Can someone lead me through creating a user object in AD.
>
> I have tried creating one through LDAP and ADSI (WinNT://) but nothing
> happens.
>
> DirectoryEntry DE = new DirectoryObject("CN=users,DC=ADomain,DC=com");
> DE.Children.Add("Philip", "user");
> DE.CommitChanges();
>
> This script does absolutely nothing. Why?
>
>
> Thanks,
> Philip
>
>
>
>[/color]


Philip Carnstam
Guest
 
Posts: n/a
#3: Nov 16 '05

re: Creating a User object in AD


The address is not the problem, I know the one entered here was not fully
correct. I can access any object, I just can't create new ones.


"Willy Denoyette [MVP]" <willy.denoyette@pandora.be> wrote in message
news:eg8uB8QbEHA.996@TK2MSFTNGP12.phx.gbl...[color=blue]
> Your DirectoryObject should at least contain a correct LDAP ADsPath;
> LDAP://HostName[:PortNumber][/DistinguishedName]
>
> In your case
> DirectoryEntry DE = new
> DirectoryObject(LDAP://serverName/CN=users,DC=ADomain,DC=com);
> Where serverName is the name of the AD server host or the domain name.
>
> Willy.
>
> "Philip Carnstam" <philip@carnstam.net> wrote in message
> news:ehq2duQbEHA.3512@TK2MSFTNGP12.phx.gbl...[color=green]
> > Hi,
> >
> > Can someone lead me through creating a user object in AD.
> >
> > I have tried creating one through LDAP and ADSI (WinNT://) but nothing
> > happens.
> >
> > DirectoryEntry DE = new DirectoryObject("CN=users,DC=ADomain,DC=com");
> > DE.Children.Add("Philip", "user");
> > DE.CommitChanges();
> >
> > This script does absolutely nothing. Why?
> >
> >
> > Thanks,
> > Philip
> >
> >
> >
> >[/color]
>
>[/color]


Marc Scheuner [MVP ADSI]
Guest
 
Posts: n/a
#4: Nov 16 '05

re: Creating a User object in AD


>DirectoryEntry DE = new DirectoryObject("CN=users,DC=ADomain,DC=com");

This is an invalid LDAP bind string..... it should be something like
this:

DirectoryEntry DE = new
DirectoryObject("LDAP://CN=users,DC=ADomain,DC=com");
[color=blue]
>DE.Children.Add("Philip", "user");[/color]

This is invalid again - you'll need to specify the user name in LDAP
style, e.g. including the cn= prefix:

DE.Children.Add("cn=Philip", "user");
[color=blue]
>DE.CommitChanges();[/color]

And before that, you will need to set at least all the mandatory
properites of the user object, which includes the samAccountName,
which has to be unique in the whole domain:

DE.Properties["sAMAccountName"].Value = "philipp";

THEN

DE.CommitChanges();

Now you should see your new user object in AD.

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Closed Thread