0

我有具有以下结构的 xml 文件。

 <NodeData>
      <XPath>//VersionInfo/VersionList[Name = "FileCopy"]</XPath>
      <Node>
        <VersionList xmlns="">
          <Name>Core_FileCopy</Name>
          <Version>10.21.1.3</Version>
        </VersionList>
      </Node>
    </NodeData>

我正在获取值版本和名称并将它们存储在日志文件中。

    $FileList= Get-Childitem -path "Z:\XmlFiles" -Include "*.xml" -recurse | ?{$_.GetType() -ne [System.IO.DirectoryInfo]} 
    $LikeArray = @("10.21.*","10.20.*","10.11.*")

    Foreach ( $File in $Filelist ) { 

        "Processing file $File.FullName"
        $xmldata= [xml] (Get-content $File.FullName);  
        $VersionLists = $xmldata.SelectNodes("//VersionList")    # Get the versionlist node

        # If it has VersionList node
        If ( $VersionLists -ne $null) {

            Foreach ($VersionList in $VersionLists) { 
$VersionList | Select Version | Where-Object {$_ -notlike $LikeArray }
            }

        }
    }

但是只有在没有版本号的情况下,我才需要存储名称和版本

("10.21. ","10.20. ","10.11.*)。

我已经修改了我的条件,但它仍然显示所有版本号

4

1 回答 1

0

看看这是否符合您的要求。

$FileList= Get-Childitem -path "Z:\XmlFiles" -Include "*.xml" -recurse | ?{$_.GetType() -ne [System.IO.DirectoryInfo]} 
$LikeArray = @("10.21","10.20","10.11")
Foreach ( $File in $Filelist ) { 
        "Processing file $File.FullName"
        $xmldata= [xml] (Get-content $File.FullName);  
        $VersionLists = $xmldata.SelectNodes("//VersionList")    # Get the versionlist node
        Foreach ($VersionList in $VersionLists) { 
         if ( $LikeArray -notcontains $VersionList.Version.substring(0,5)) {
                    $VersionList | select Name, Version 
               }
        }
}
于 2012-10-30T16:35:06.640 回答