Handling Multivalue Attributes from a powershell runspace?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello,
I am not having any trouble getting the property values. No exceptions are occuring. What I am having trouble with is getting the multivalue properties values out as individual items. I have been attempting to use the code example from: http://blogs.msdn.com/b/webdav_101/archive/2008/02/08/handling-results-of-calling-powershell-multivalued-and-string-arrays.aspx http://blogs.msdn.com/b/webdav_101/archive/2008/02/08/handling-results-of-calling-powershell-multivalued-and-string-arrays.aspx
which I have appended below. Unfortunately in the case of the EmailAddresses attribute from a Get-Mailbox command, the multivalue properties which are returned as type: PSObject are not "Castable" to an ICollection. It is not clear to me how to access
the individual items in the PSObject that is returned. What I am after is the indivdual EmailAddress Values. If you use the propertyValue.ToString() method as I have shown in the example you get a string with the following format: {smpt:address@domain.com
SMTP:anotheraddress@domain.com} while I could split this string into the individaul values using the space as a delimiter I am not comfortable with that technique. I would like to be able to handle (in a general sense) multivalue attributes as
Arrays or ArrayLists.
Again there are no errors occuring in my current code. I just want to improve its handling of multi-value attributes when they are returned.
Thanks
Bill

<pre style="background:white; color:black; font-family:Consolas <span style="color:green //==============================================================================================
<span style="color:green // DumpAllProperties
<span style="color:green //==============================================================================================

<span style="color:blue static <span style="color:blue void DumpAllProperties(<span style="color:blue ref ICollection<PSObject> results)

{
<span style="color:green // === All properties =================================================================


<span style="color:green // Use this foreach for getting all properties:

Trace.WriteLine(<span style="color:#a31515 "n");

Trace.WriteLine(<span style="color:#a31515 "------=======***************************=======------");
Trace.WriteLine(<span style="color:#a31515 "------=======***** ALL PROPERTIES ****=======------");
Trace.WriteLine(<span style="color:#a31515 "------=======***************************=======------");

Trace.WriteLine(<span style="color:#a31515 "n");

<span style="color:blue foreach (PSObject result <span style="color:blue in results) <span style="color:green // process result set.
{
<span style="color:blue foreach (PSProperty prop <span style="color:blue in result.Properties)
{
String propName = prop.Name;
Object propValue = prop.Value;

<span style="color:green //string strMsg;

<span style="color:blue if (propValue != <span style="color:blue null)
{
Trace.WriteLine(<span style="color:#a31515 "----[Begin: " + prop.Name + <span style="color:#a31515 "]---------------------------------n");
Trace.WriteLine(<span style="color:#a31515 " TypeNameOfValue: " + prop.TypeNameOfValue + <span style="color:#a31515 "");
Trace.WriteLine(<span style="color:#a31515 " MemberType: " + prop.MemberType.ToString() + <span style="color:#a31515 "");
Trace.WriteLine(<span style="color:#a31515 " ");
<span style="color:blue if (propValue <span style="color:blue is ICollection)
{
ICollection collection = (ICollection)propValue;
Trace.WriteLine(<span style="color:#a31515 " Multi-valued Property:");
<span style="color:blue foreach (<span style="color:blue object value <span style="color:blue in collection)
{
Trace.WriteLine(<span style="color:#a31515 " Value: " + value.ToString() + <span style="color:#a31515 "");
}
Trace.WriteLine(<span style="color:#a31515 "");
}
<span style="color:blue else
{
Trace.WriteLine(<span style="color:#a31515 " Value: " + propValue.ToString() + <span style="color:#a31515 "");
Trace.WriteLine(<span style="color:#a31515 "");
}
}
}
}
}[/code]

View the full article
 
Back
Top