updating proxyAddresses
I need to add to my rules extension code for Active Directory for when an email address changes. I need to be able to loop through the proxyAddresses and change any values in this attribute to reflect the new email address.
Can you point me to where I can see sample C# code on how this is done?
Thanks.
November 18th, 2010 1:59pm
This is a VB example for working with proxyAddresses
If mventry("proxyAddresses").Values.Contains(<any expression>)) Then
<Your Code, for example add a value to the csentry attribute>
csentry("proxyAddresses").Values.Add("smtp:" & csentry("whatever")
End If
For Each mailAddress In mventry("proxyAddresses").Values
<Your Code>
Next
/Matthias
Free Windows Admin Tool Kit Click here and download it now
November 19th, 2010 2:10am
Thanks, that helps. I'm really looking for the C# equivalent.
November 19th, 2010 8:22am
Here you go. Note it makes the ssumption that csentry["proxyAddresses"] exists in the first code block. Otherwise you'll need to initialize a new value collection first.
if (mventry["proxyAddresses"].IsPresent && mventry["proxyAddresses"].Values.Contains("stuff"))
{
csentry["proxyAddresses"].Values.Add("smtp:" + csentry["foo"].Value)
}
foreach string address in mventry["proxyAddresses"].Values
{
// do stuff
}My Book - Active Directory, 4th Edition
My Blog - www.briandesmond.com
Free Windows Admin Tool Kit Click here and download it now
November 19th, 2010 11:58am
Brian -
I don't believe I'm going to be adding entries, only changing the values of the existing entries due to a change of name or email address. So I'm assuming there's some sort of replace function that I would use to do this? Sorry, I'm very new to C#.
November 19th, 2010 3:05pm
Basically you want something like this then:
ValueCollection values = new ValueCollection("placeholder");
values.Clear()
values.Add("SMTP:primaryaddr@domain.com")
values.Add("smtp:secondaryAddr@domain.com")
csentry["proxyAddresses"].Values = values;
My Book - Active Directory, 4th Edition
My Blog - www.briandesmond.com
Free Windows Admin Tool Kit Click here and download it now
November 19th, 2010 3:29pm
So I'm gathering from your example that there is no way of manipulating a multi-value attribute (i.e. replace the values in place?) and the only solution is to clear out the values and re-add them in the way you specified?
I cannot seem to get this bit of code to work:
foreach (string mailAddress in mventry["proxyAddresses"].Values)
{
//do stuff
}
*Cannot convert type 'Microsoft.MetadirectoryServices.Value' to 'string'
November 22nd, 2010 10:53am
So I'm gathering from your example that there is no way of manipulating a multi-value attribute (i.e. replace the values in place?) and the only solution is to clear out the values and re-add them in the way you specified?
Free Windows Admin Tool Kit Click here and download it now
November 22nd, 2010 10:54am
Clearing it out and reloading them is the easiest. FIM will only actually send the effective changes when it exports.
Replace string mailAddress with Value mailAddress.My Book - Active Directory, 4th Edition
My Blog - www.briandesmond.com
November 22nd, 2010 2:19pm