Adding Custom Attributes in Active Directory
Pre-requisites
Enable Schema Updates by Means of the Registry:
1. | Click Start, click Run, and then in the Open box, type: regedit
|
2. | Locate and click the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NTDS\Parameters |
3. | On the Edit menu, click New, and then click DWORD Value. |
4. | Enter the value data when the following registry value is displayed: Value Name: Schema Update Allowed |
5. | Quit Registry Editor. |
Follow these steps to configure attributes
- Install the Schema snap-in (Start, Run, regsvr32 schmmgmt.dll).
- Go to Start -> Run -> Type MMC and press Enter
- Go to File -> Add/Remove Snap-in -> click Add -> Select Active Directory Schema and click Add
- Expand the Active Directory schema and Right Click Attributes
- Click “Create Attribute”
- Create New Attribute window will appear
- In Common name enter “ROLLNUMBER”
- Enter LDAP name also as “ROLLNUMBER”
- Get OID please refer http://msdn2.microsoft.com/en-us/library/ms677620.aspx
- For our demo we have used DUMMY Values like 1.2.3.4.5
- Select the appropriate syntax, which in our case may be INTEGER. Assuming that in ROLLNUMBER we have all INTEGER Values.
- Mention Minimum and Maximum values if required. These are optional you can leave them blank.
- Once created your attribute will look as below
- Once Attribute is created, select Classes
- Expand CLASSES and Select PERSON
- Rick click PERSON and select Properties
- Click Attribute Tab and click Add
- Select the Attribute you created and click OK.
- Click OK to close all property windows
- Goto Start ->Run -> Type ADSIEDIT.MSC. For running this command you may need to install the support tools from the Windows installation CD.
- Open the Active Directory Service Interfaces (ADSI) Edit utility, then navigate to Configuration Container, CN=Configuration,
- Click CN=DisplaySpecifiers
- Click CN=409.
- In the right-pane, locate and right-click CN=user-display, and select Properties.
- Select AdminContextMenu and click EDIT
- In the Edit Attribute box, type the following:
27. Enter the following in the Empty box and Click Add
3,&ROLL NUMBER, c:\EnterAttrib.vbs
Note:
3 is the serial number
&ROLL NUMBER is the Attribute which will appear in User and Computers context Menu
C:\EnterAttrib.vbs is the script which will add the value to attribute
Please do not change the Syntax
- Click OK to close all window popups
- Select Configuration in ADSIEDIT panel and Right Click
- Click “UPDATE SCHEMA NOW”
- These steps configure the options ROLL NUMBER on the context menu for a user in the Microsoft Management Console (MMC) Active Directory Users and Computers snap-in.
- You must write and place the following scripts on your C drive or somewhere else in your file path:
Dim oVar
Dim oUsr
Dim tmp
Set oVar = Wscript.Arguments
Set oUsr = GetObject(oVar(0))
tmp = InputBox("The Roll Number of the user is: " & oUsr.ROLLNUMBER & vbCRLF & vbCRLF & “Enter the new Roll Number Below“)
if tmp <> "" then oUsr.Put "ROLLNUMBER",tmp
oUsr.SetInfo
Set oUsr = Nothing
WScript.Quit
How To Add Custom Attributes to the Directory Service Find List
1. | Use ADSIEdit to select the Configuration namespace. |
2. | Expand the displaySpecifier container. |
3. | Expand the appropriate displaySpecifier container. For example, "409" is English. |
4. | View the Properties for the user-Display object. |
5. | Modify the attributeDisplayNames attribute by adding a value in the format: Your_new_Attribute,friendly_name For example, "Roll Number" looks like this: ROLLNUMBER,Roll Number |
安装 Active Directory 架构 MMC 管理单元
1.
2.
该命令将在计算机上注册“schmmgmt.dll”。
3.
4.
5.
增加扩展属性
1. 右键点击“Attributes”,选择“New”—“Attribute”。
2.填写”Common Name”,”Object ID”,”描述”,语法选择”Unicode String”,最后点击“OK”
3.在”类别”中找到“user”标签,右键点击,选择“Properties”
4.在Attributes页点击“Add”。
5.选择新增的属性,点击“OK”后,再点击属性页的“OK”。
6.扩展属性增加完毕。
Setting up AD by scripting
How to run script
Note: This script must be run on AD server.
- open a windows cmd, go to the folder where the script file is located, and execute command:
ldifde -i -v -f <script file name> -j <log folder>
- Example:
ldifde -i -v -f initialization_AD.ldf -j c:
for more detailed info on ldifde cmd, please refer to Ldifde
Partial Script Description
Note: you need to modify the script to match your Active Directory environment before you run the script, such as DN, attribute name etc.
The following script is a sample to create an attribute. Basically, you need to modify DC, CN to match your Active Directory environment. You need to use owned attributeID. Please refer toSyntax the value you should set for attributeSyntax and oMSyntax. Also you can add more properties to attributes, and please refer toattributeSchema for the definition of each property.
dn: CN=npi,CN=Schema,CN=Configuration,DC=hsiplab,DC=local
changetype: add
objectClass: top
objectClass: attributeSchema
cn: npi
attributeID: 2.1.1.1
attributeSyntax: 2.5.5.12
isSingleValued: TRUE
oMSyntax: 64
searchFlags: 0
isMemberOfPartialAttribu teSet: TRUE
dn:
changetype: modify
replace: schemaupdatenow
schemaupdatenow: 1
-
The following script is a sample to assign attributes to User class. Similarly, you need to modify DC. You need to add attributeID to mayContain to indicate what attribute you want to add to the User class.
dn: CN=User,CN=Schema,CN=Configuration,DC=hsiplab,DC=local
changetype: Modify
add: mayContain
mayContain: 2.1.1.2
-
dn:
changetype: modify
add: schemaUpdateNow
schemaUpdateNow: 1
-
The following script is a sample to create an OU, and create a group under the OU. You just need to change CN and DC to match your environment.
# ---------------------------------------------------------------------- # This section create OU and Groups, # ---------------------------------------------------------------------- # Create an OU, name is CIN dn: ou=CIN, DC=hsiplab,DC=local changetype: add
# Create a group under OU=CIN dn: cn=ClinicalAdmin,ou=CIN, DC=hsiplab,DC=local changetype: add objectclass: top objectclass: group cn: ClinicalAdmin sAMAccountName: ClinicalAdmin
You can refer to the Microsoft official website LDIFDE for some good samples.
Disadvantage of Using Script
The biggest disadvantage of script is it cannot be rolled back. The script file is sequentially executed based on the script order in the file. It will be broken once an error happens, such as a syntax error. It cannot be rolled back if there are tasks executed successfully before the error happens. Once this situation happens, it means you have to correct the error, and comment those scripts which are executed successfully earlier, and then run the script file again. One alternative solution is to separate tasks into different script files with one standalone task in each script file, and run the script files one by one. You only need to correct the file that contains an error.