library (DLL) in C# and use it in Ax. It works fine for me at least.
Here is the C# code I used:
————————————
using System;
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;
namespace Microsoft.Dynamics.CreateADUser
{
public class NewUser
{
string defaultNC;
string alias;
string fullName;
string password;
string ou;
public void setDomain(string _defaultNC)
{
defaultNC = "DC=" + _defaultNC;
}
public void setAlias(string _alias)
{
alias = _alias;
}
public void setFullName(string _fullName)
{
fullName = _fullName;
}
public void setPassword(string _password)
{
password = _password;
}
public void setOu(string _ou)
{
ou = _ou;
}
public string execute()
{
DirectoryEntry container, user;
string ret;
try
{
//This creates the new user in the "users" container.
//Set the sAMAccountName and the password
container = new DirectoryEntry("LDAP://OU=" + ou + ", " +
defaultNC + ",DC=NO");
user = container.Children.Add("cn=" + fullName, "user");
user.Properties["sAMAccountName"].Add(alias);
user.CommitChanges();
user.Invoke("SetPassword", new object[] { password });
//This enables the new user.
user.Properties["userAccountControl"].Value = 0x200;
//ADS_UF_NORMAL_ACCOUNT
user.CommitChanges();
ret = "OK";
}
catch (Exception e)
{
ret = e.ToString();
}
return ret;
}
}
}
————————————
Just compile and put the dll-file in the client\bin folder of Ax and create
a reference from the aot and use the class like this in Ax:
————————————
static void Job1(Args _args)
{
Microsoft.Dynamics.CreateADUser.NewUser user;
;
user = new Microsoft.Dynamics.CreateADUser.NewUser();
user.setDomain(/*yourdomain*/);
user.setAlias(/*alias of the user you want to create*/);
user.setFullName(/*Full name of the user*/);
user.setPassword(/*Password*/);
user.execute();
}
————————————
Regards,
Erlend
"Max Belugin [MVP]" wrote:
> I think, you can find and example in C# and port it to X++
>
> http://www.google.com/search?q=create+user+active+directory+C%23
>
> —
> my blog: http://axcoder.blogspot.com
> freeware sidebar for ax: http://belugin.info/sidax
>
>
> "Erlend Dalen" wrote:
>
> > Is it possible to create a new user in AD from Ax 4.0?
> > I have been looking into the System.DirectoryServices, but I haven’t been
> > able to figure out to make it work yet….can anyone help?
> >
> > Regards,
> > Erlend