This topic contains 8 replies, has 3 voices, and was last updated by
March 20, 2015 at 6:36 pm #23543
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).
March 20, 2015 at 8:27 pm #23545ParticipantPoints: 0Rank: Member
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.
March 20, 2015 at 8:39 pm #23546
How do you display xml tags in this forum?
March 20, 2015 at 11:18 pm #23547ParticipantPoints: 0Rank: Member
I'd just attach as a text file.
March 22, 2015 at 3:55 am #23566
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?
March 26, 2015 at 11:18 pm #23709ParticipantPoints: 0Rank: Member
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.
March 24, 2015 at 3:33 am #23626
Maybe this is a bug? Has anyone used an xmlelement object as the input to an addrange parameter?
March 25, 2015 at 12:00 pm #23688
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"?
March 27, 2015 at 6:12 am #23720
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.
The topic ‘Form addrange method, xml and object types’ is closed to new replies.