10.4. Generating a GUID to Use for a New Class or Attribute

Problem

You want to generate a GUID to use for the schemaIDGUID attribute of a new class or attribute you intend to add to the schema.

Solution

There are several ways to go about generating a GUID. If you do not specify the schemaIDGUID when initially creating a class or attribute, one will automatically be generated for you. So you could add the class or attribute to the schema of a test forest, and then use the schemaIDGUID that was generated in that forest.

You can also programmatically generate a GUID using Perl, VB, C++, or C#, but you cannot do it natively within VBScript. The Windows API supports a CoCreateGUID method that can be used to generate a GUID. If you are stuck with VBScript, you can wrap the CoCreateGUID method in an ActiveX DLL using VB and then use that DLL from within VBScript.

Finally, you can use a tool such as uuidgen.exe, which is available in the Microsoft Platform SDK to generate GUIDs. Uuidgen doesn’t require any parameters (although there are a few options that can be seen by running uuidgen -h), and it can generate as many GUIDs as you need.

If you intend to use LDIF files for extending the schema (highly recommended), then you need to encode any GUIDs in base64 notation. This is necessary because GUIDs are stored as octet strings (binary data) in Active Directory. The LDIF specification requires any binary data to be encoded in base64. Again, VBScript does not support base64 encoding natively, but ...

Get Active Directory Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.