Powershell:在XML中替换所有节点的值

时间:2018-06-04 09:29:07

标签: xml powershell

我想替换所有表达式=

的内容

如果没有与'' Where'匹配的重复节点,我在下面测试的代码是有效的。条件。

但是如果有重复项,则错误是'在此对象上找不到属性表达式':

下面是替换表达式=:

的powershell代码
param([String]$twb_path='D:\auto\',
    [String]$twb_name='Location_Geo (3).twb',
    [String]$replace_var='test@email',
    [String]$action_name='Click to go to Support') 

$xml=New-Object System.XML.XMLDocument 
$xml.Load($twb_path+'temp\wb\'+$twb_name) 

$xml.GetType().FullName
Select-Xml -Xml $xml -XPath "./workbook" | Select-Object -ExpandProperty Node 
$node = $xml.workbook.actions.action | Where-Object {$_.caption -eq $action_name}
$node.link.expression = $replace_var

以下是XML的外观:

<action caption="Click to go to Support" name="[Action13]">
      <activation type="on-select" />
      <source dashboard="003-A2: Detailed List " type="sheet" worksheet="Support Icon" />
      <link caption="Click to go to Support" expression="mailto: emailadd" />
    </action>
<action caption="Click to go to Support" name="[Action14]">
      <activation type="on-select" />
      <source dashboard="some dashboard" type="sheet" worksheet="Support Icon" />
      <link caption="Click to go to Support" expression="mailto: emailadd" />
    </action>

0 个答案:

没有答案