Form addrange method, xml and object types

Last week I finally got the opportunity to use Powershell Studio. I have been given a huge AD management project and am having fun learning all the controls, methods and properties.
My question is - how can you check if an object “type” is suitable for the addrange method on a combobox?

One of my forms has two combo boxes. One is populated using an ad search.
I use the searcher object and the findall method piped into a select statement to create two properties called “display” and “value” (lets call the object $adresults).
This object is the parameter to the addrange method and the “display” is assigned to displaymember and “value” is assigned to valuemember of the combobox.
The values are displayed fine and the values are selected perfectly as expected.

The next combobox I am trying to populate from xml elements. I do a:
[xml]$config = get-content (c:\config.xml).
The path $config.accounttype.status has seven instances and each has two child elements called “display” and “value”. These two display as properties when I enter $config.accountype.status.
I use that path as the input to the addrange method and do the same for the displaymember and valuemember as I did for the AD object.
Problem here is that instead of displaying the values contained in the “display” property, the text that is displayed is the typename of the object (xmlelement).

I checked the addrange method help and it says it expects a system.object which seems like a a fairly generic superclass.
I did a getype() and gettype().basetype on both my $adresults and $config.accounttype.status objects and I get the same result!
The typename of the ad object is adsearcher and the typename of the xml object is xmlelement.

So my questions are as follows:
Why does the xml object result in a display of the typename and not the display property?
What command or help can I consult to determine if an object is suitable as input to a method? (In the interest of debugging this type of thing in the future)
As the addrange method does not appear to like my xml object, what’s the quickest way to convert this to a generic object? (im using a foreach and new-psobject and adding to array type stuff - just wondering if there’s anything quicker).


David Z

Hey David,

Can you post a sample XML file content?

For object suitability, I’d suggest going down the Try…Catch route. You can do a generic Catch (i.e. catching System.Exception), or finely tune it to detect certain exceptions such as InvalidCastException or ArgumentTransformationMetadataException.

How do you display xml tags in this forum?

I’d just attach as a text file.

Its a rather unremarkable xml file and I dont think its a clue to the issue.
I have always heard that one can always find the answer through examination and help files so Im still keen on getting the answer to the generic question of how you can determine if an object is suitable as an input to a method.
And more specifically why the addrange method in my example seems to “ignore” my object and display the typename?


david z

Maybe this is a bug? Has anyone used an xmlelement object as the input to an addrange parameter?

Maybe a more basic explanation will help.
In the MSDN documentation it says that the addrange method accepts a “system.object”.
What does that mean exactly and how do you know if any given object is a “system.object”?



Maybe it’s a bug, maybe not. But I don’t see a point of not sharing example file so people can try it also and not just tak of hypotetical stuff.

Good question is half of the answer.
My question was that the xmlelement type is not compatible with the addrange method. Therefore any xml file will do as an example.