Powershell错误“无法设置”属性”,因为仅字符串可以用作设置XmlNode属性的值

Rya*_*sen 3 powershell soap

在将值分配给XML的SOAP调用时遇到问题。该值在变量中定义,但Powershell不断返回此错误:

“无法设置“属性”,因为只能将字符串用作设置XmlNode属性的值”

我的变量定义为字符串: [string]$AvidDisplayNameMinusTransfer

这是带有变量的SOAP调用:

$soap = [xml]@'

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://avid.com/interplay/ws/assets/types">
   <soapenv:Header>
      <typ:UserCredentials>
         <typ:Username>***</typ:Username>
         <typ:Password>***</typ:Password>
      </typ:UserCredentials>
   </soapenv:Header>
   <soapenv:Body>
      <typ:Search>
         <typ:InterplayPathURI>interplay://AvidEng103/LTW</typ:InterplayPathURI>
         <typ:SearchGroup Operator="AND">
            <!--Zero or more repetitions:-->
            <typ:AttributeCondition Condition="EQUALS">
               <typ:Attribute Group="USER" Name="Display Name"></typ:Attribute>
            </typ:AttributeCondition>
         </typ:SearchGroup>
         <typ:ReturnAttributes>
            <typ:Attribute Group="SYSTEM" Name="MOB ID"></typ:Attribute>
         </typ:ReturnAttributes>
      </typ:Search>
   </soapenv:Body>
</soapenv:Envelope>

'@

$soap.Envelope.Body.Search.SearchGroup.AttributeCondition.Attribute = $AvidDisplayNameMinusTransfer
Run Code Online (Sandbox Code Playgroud)

让我知道是否有人需要我的整个代码来提供更好的上下文。

Ans*_*ers 5

使用innerText属性将字符串分配为标签的内容:

$soap.Envelope.Body.Search.SearchGroup.AttributeCondition.Attribute.innerText = $AvidDisplayNameMinusTransfer
Run Code Online (Sandbox Code Playgroud)

结果:

$soap.Envelope.Body.Search.SearchGroup.AttributeCondition.Attribute.innerText = $AvidDisplayNameMinusTransfer
Run Code Online (Sandbox Code Playgroud)