如何将 foreach 语句的结果传输到文本文件?

如何将 foreach 语句的结果传输到文本文件?

如何将下面脚本的结果导入到 list.txt 中?

$folder = 'C:\Test'
$Total = $Files = 0

foreach($File in (Get-ChildItem -Path $Folder -Filter *.pdf)){
    $Pages = (pdfinfo $File.FullName | Select-String -Pattern '(?<=Pages:\s*)\d+').Matches.Value
    $Total += $Pages
    $Files++
    [PSCustomObject]@{
        PdfFile = $File.Name
        Pages   = $Pages
    }
}
"`nTotalNumber of pages: {0} in {1} files" -f $Total,$Files

相关内容