i have a problem adding values to an xml array property. The xml looks like this:
$xml = [xml]@"
<letters>
<letter><to>mail a</to></letter>
<letter>
<to>mail a</to>
<to>mail b</to>
</letter>
</letters>
"@
$letter = $xml.letters.letter[1]
$letter.to
#mail a
#mail b
now i want to add items ("mail c", "mail d") to the "to" array:
$letter.to
#mail a
#mail b
#mail c
#mail d
But i don't seem to be able to.
a) simply trying to set anything to the property results in a misleading error:
$letter.to += "a"
#"to" kann nicht festgelegt werden, da nur Zeichenfolgen als Werte zum Festlegen von XmlNode-Eigenschaften verwendet werden können.
#Bei Zeile:1 Zeichen:9
#+ $letter. <<<< to += "a"
# + CategoryInfo : InvalidOperation: (:) [], RuntimeException
# + FullyQualifiedErrorId : PropertyAssignmentException
But that probably boils down to "to" not having a setter:
$letter | Get-Member
#Name MemberType Definition
#[bunch of stuff]
#to Property System.Object[] {get;}
b) Setting a value via SetAttribute partly works, but results in unusable (and very strange) behaviour:
$letter.SetAttribute("to", "mail c")
$letter.to
#mail c <- why is it up front?
#mail a
#mail b
$letter.SetAttribute("to", "mail d")
$letter.to
#mail d <- why is mail c gone?
#mail a
#mail b
Does anyone have an Idea what to try next?