首页 > 解决方案 > 解析 XML 以导出到 CSV

问题描述

从 XML 格式的 IIS 配置文件中获取我想要的数据时遇到问题。本质上,我需要获取一堆受限 IP 地址以及 webappname 中的 4 个数字,即(示例/3780)名称并导出到 csv。

XML 示例

 <location path="Example/3780_Proxy_Test_01418277">
    <system.webServer>
        <security>
            <ipSecurity>
                <add ipAddress="10.10.199.20" allowed="true" />
                <add ipAddress="10.10.81.80" subnetMask="255.255.255.240" allowed="true" />
                <add ipAddress="10.10.199.16" subnetMask="255.255.255.240" allowed="true" />
                <add ipAddress="10.10.163.150" allowed="true" />
                <add ipAddress="10.10.163.151" allowed="true" />
            </ipSecurity>
        </security>
    </system.webServer>
</location>
<location path="Example/3200_Proxy">
    <system.webServer>
        <security>
            <ipSecurity>
            </ipSecurity>
        </security>
    </system.webServer>
</location>

现在我被困在基础上,只是想得到任何匹配的东西

$path = "\path\to\whatever.xml"
$xpath = "/configuration/location/system.webserver/security/ipsecurity"
select-xml -path $path -xpath $xpath |select-object ipaddress

标签: xmlpowershell

解决方案


推荐阅读