Set Active Directory 'company' value to NULL??

  • Thread starter Thread starter Phil Kelly
  • Start date Start date
P

Phil Kelly

Hi!

Is it possible to set the value of an Active Directory attribute to be
empty?

I've tried to set the 'company' attribute as follows:
myRepEntry.Properties(strAttrName)(0) = Nothing

but I get an error stating that the value cannot be NULL.

Anyone got any ideas?

Thanks for your help!

Phil
 
Download microsofts ADSI Scriptomatic, look the at examples for SetEx, the
concept is the same.
Jared
 
But surely that's using ADSI when I'm in vb - why can I not simply use:
myRepEntry.Properties(strAttrName)(0) = vbNull
If I pass the value "company" to the variable straAttrName.... surely that
should work. Or am I being stupid???
 
Phil,
I have to say that I have never tried to clear a value using .Net, most of
the time I just write a quick script so I was unsure of the actual outcome.
I created a simple project in which I directly set the value and it works
fine.

First, on single valued fields, just set the property value and commit.
'Check ADSIEdit value should appear as <not set>
myRepEntry.Properties("company").Value = vbNullString
myRepEntry.CommitChanges

On muitivalued fields you need to create a new system.array object and
remove the items you don't want to include or set the value to vbNullString
to clear evertying.

Secondly, if you know the attribute can only contain a single value why
specify the index?
myRepEntry.Properties(strAttrName)(0) vs.
myRepEntry.Properties(strAttrName).Value

You can test to see if the attribute is multivalued by checking the value
against system.array, I think that a multivalued attribute that has only a
single value specified is stored as a string and not an array but I'm not
sure.

If TypeOf Entry.Properties("otherHomePhone").Value Is System.Array Then
Dim PhoneNumbers As System.Array =
Entry.Properties("otherHomePhone").Value
Else
Dim PhoneNumber as String = Entry.Properties("otherHomePhone").Value
End If
 
Back
Top