Hi All,
I’ve been making a few scripts lately to modify a user using Javascript rather than VB.
I prefer working with Javascript as it suits my purpose a bit better as I can use variable size arrays to make it do what I want.
I start off with the Distinguished Name (DN) of the object, which can be obtained with :
function GetDN(strUsername) {
var rootdse = GetObject("LDAP://RootDSE");
var objUserDN = new ActiveXObject("NameTranslate");
objUserDN.Init(1,"DOMAIN NAME HERE");
objUserDN.Set(3,"DOMAIN NAME HERE\\"+strUsername);
strUserDN = objUserDN.get(1)
return strUserDN;
}
That code will get the DN of the user in question. Whether you integrate it into the script itself or use a function that is seperate from the main script is up to you.
I have used a function in this case.
*Update*
I have posted a way to obtain the Domain Name for this script here.
After you have obtained the DN of the user, you will now need to create an object for the user so we can manipulate the user’s details.
var objUser = GetObject("LDAP://"+strUserDN);
We can now access the properties of the user via the objUser
object.
To see what the properties contain already, you can use this :
var strUserDesc = objUser.description;
To modify any properties, the put method is used :
objUser.Put("description","This is the new description");
objUser.Put("profile","This is the new profile path");
objUser.SetInfo();
The SetInfo method is used to commit changes into AD.
Hopefully no errors will come up when you try to commit the changes, and you have successfully modified a user using Javascript !.
All the properties can be found on the MSDN (reference 4).
Reference :
1. IADsNameTranslate Interface
2. ADS_NAME_INITTYPE_ENUM Enumeration
3. ADS_NAME_TYPE_ENUM Enumeration
4. IADsUser Interface
Hi,
Do you know how can update a machine description in AD with javascript?
thanks in advance,
Mapache
You can do it with the same principle as this script.
I haven’t done it myself in a while so I can’t remember exactly what is needed unfortunately. Sorry !