AD Octet String

A

AstroDrabb

I am trying to update some Active Directory attributes in C#. The C# app creates new computer objects and then populates some attributes. However, I am having problems with one attribute named netbootGUID, which is of type Octet String in AD. I haven't been able to find any working examples on the web. Part of the code follows:

DirectoryEntry entry = new DirectoryEntry(path, m_UserName, m_Password);

DirectoryEntry dChild = entry.Children.Add("CN=" + name, className);

// add attributes
dChild.Properties["sAMAccountName"].Value = name + "$";
dChild.Properties["serialNumber"].Value = serial;

string guid = "4E435220000000000000054012345678"

// this doesn't work
dChild.Properties["netbootGUID"].Clear();
dChild.Properties["netbootGUID"].Add(guid);
// neither does this
dChild.Properties["netbootGUID"].Value = guid;

From what I can tell the netbootGUID attribute needs to be set as a byte[]. I tried converting the guid string to a byte[], I tried converting each char in guid to hex and then putting it into a byte[], however none of it has worked.

Does anyone have an example of updating an Octet value in AD with C#?

Thanks for any help.
 
A

AstroDrabb

For anyone who is interested, I found the solution.

Mandatory attributes need to be written first and then you have to call CommitChanges(). For example:

entry = new DirectoryEntry(path, m_UserName, m_Password);
dChild = entry.Children.Add("CN=" + name, className);

// add attributes
dChild.Properties["sAMAccountName"].Value = name + "$";
dChild.Properties["serialNumber"].Value = serial;
// new security in AD requires a commit here after setting
// the mandatory attributes
dChild.CommitChanges();

string guid = "4E435220-0000-0000-0000-054012345678"
Guid myGuid1 = new Guid(guid);
dChild.Properties["netbootGUID"].Clear();
dChild.Properties["netbootGUID"].Add(myGuid1.ToByteArray());
dChild.CommitChanges();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top