#region Define regex results [regex]$whiteWin = '\[Result "1-0"\]' [regex]$blackWin = '\[Result "0-1"\]' [regex]$Tie = '\[Result "1/2-1/2"\]' #endregion #region Main Process All pgn files Get-ChildItem -Path C:\Users\Irwin\Downloads\ChessData-master\ChessData-master -File *.pgn -Recurse | ForEach-Object { $pgnFile = Get-Content $_.FullName -Raw [PSCustomObject]@{ FileReference = $_.Name WhiteWin = ($whiteWin.Matches($pgnFile)).Count BlackWin = ($blackWin.Matches($pgnFile)).Count Tie = ($Tie.Matches($pgnFile)).Count } } | Export-Csv .\export\ChessMatchesResults.csv -Delimiter "`t" -NoTypeInformation #endregion