【发布时间】:2019-11-18 08:11:56
【问题描述】:
这是 API 调用的预定义变量。
$CorePluginConfigurationContext = ([xml]"
<CorePluginConfigurationContext xmlns='http://schemas.solarwinds.com/2012/Orion/Core' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
<BulkList>
<IpAddress>
<Address></Address>
</IpAddress>
</BulkList>
</CorePluginConfigurationContext>
").DocumentElement
阅读 PowerShell 书籍、在线文档、XML 命名空间、Nodes、Parents、Childs、Appending、“element”“s”,我根本无法向这个特定变量添加数据。
我得到多个值作为参数
Param(
[Parameter(Mandatory=$true)]
[String[]]$nodes = "1.1.1.1"
)
并且需要将这些值添加到 XML 对象中。
foreach ($node in $nodes) { }
结果会是这样的:
<CorePluginConfigurationContext xmlns='http://schemas.solarwinds.com/2012/Orion/Core' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
<BulkList>
<IpAddress>
<Address>10.10.1.19</Address>
</IpAddress>
<IpAddress>
<Address>10.10.1.20</Address>
</IpAddress>
</BulkList>
</CorePluginConfigurationContext>
测试代码:
Param (
[Parameter(Mandatory=$true)]
[String[]]$nodes = "1.1.1.1"
)
$CorePluginConfigurationContext = ([xml]"
<CorePluginConfigurationContext xmlns='http://schemas.solarwinds.com/2012/Orion/Core' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
<BulkList>
<IpAddress>
<Address></Address>
</IpAddress>
</BulkList>
</CorePluginConfigurationContext>
").DocumentElement
foreach ($node in $nodes) {
# Code to add multiple $node values to the XML above
}
【问题讨论】:
-
很遗憾你没有发布你已经尝试过的代码,所以很难说你的问题是什么。所以请edit您的问题并添加您的代码。同时也许this might be helpful
标签: xml powershell