如果你想使用点符号,你可以这样做:
$node = $appConfig.configuration.connectionStrings.add | Where-Object {$_.name -eq $dbName} $node.connectionString = $updatedConnectionString $appConfig.Save()
或者像这样(如果您不想在修改其属性之前将所选节点分配给变量):
($appConfig.configuration.connectionStrings.add | Where-Object {$_.name -eq $dbName}).connectionString = $updatedConnectionString $appConfig.Save()
另一种方法是将该SelectSingleNode()
方法与XPath表达式一起使用,例如:
($appConfig.SelectSingleNode("//add[@name='$dbName']").connectionString = $updatedConnectionString $appConfig.Save()