0

The problem is the following:

$xml = [xml](Get-Content $USSExternalContentTypeFile)   
$xml.Model.Properties.Property. ....
$xml.Save($USSExternalContentTypeFile)   

Name Type #text
---- ---- -----
Connect Integrated Security System.String textxtxtxtxtxtxtxt

<Property Name="Connect Integrated Security" Type="System.String">SSPI</Property>

Help multiple xml attribute to replace #text?

Finish: Property[2].'#text' = 'foo'

Sergei Shardiko
  • 115
  • 1
  • 3
  • 9

2 Answers2

4

Try this way to access the #text property:

PS> $xml = [xml]'<Property Name="Connect Integrated Security" Type="System.String">SSPI</Property> '
PS> $xml.Property

Name                                    Type                                    #text
----                                    ----                                    -----
Connect Integrated Security             System.String                           SSPI

PS> $xml.Property.'#text' = 'foo'

PS> $xml.Property

Name                                    Type                                    #text
----                                    ----                                    -----
Connect Integrated Security             System.String                           foo
Keith Hill
  • 194,368
  • 42
  • 353
  • 369
1

As an alternative to PowerShell's automatic NoteProperties for XML nodes you could also use XPath to get the nodes you want. Say if you want all Property nodes with a name attribute of "Connect Integrated Security" you could use:

$nodes = $xml.SelectNodes("//Property[@Name='Connect Integrated Security']")
$nodes | % {
    $_."#text" = "SomeNewValue" # Changes SSPI to this.
}

If you want to stick with the NoteProperties this will probably work:

$xml.Model.Properties.Property | % {
    $_."#text" = "SomeNewValue" # Changes SSPI to this.
}
Andy Arismendi
  • 50,577
  • 16
  • 107
  • 124