次の構造を持つ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.*)。
条件を変更しましたが、それでもすべてのバージョン番号が表示されます