Loops 导出CSV powershell循环

Loops 导出CSV powershell循环,loops,powershell,csv,Loops,Powershell,Csv,从循环输出到CSV文件的正确做法是什么。我的目标是检查与一系列扩展名匹配的所有文件的属性,这些扩展名在一个多月内未被访问,并输出到csv文件以供以后读取 它只输出第一个文件的信息。以及以下错误: Add-Member : Cannot add a member with the name "FileName" because a member with that name already exists. If you want to overwrite the member a nyway, u

从循环输出到CSV文件的正确做法是什么。我的目标是检查与一系列扩展名匹配的所有文件的属性,这些扩展名在一个多月内未被访问,并输出到csv文件以供以后读取

它只输出第一个文件的信息。以及以下错误:

Add-Member : Cannot add a member with the name "FileName" because a member with that name already exists. If you want to overwrite the member a
nyway, use the Force parameter to overwrite it.
At C:\Users\claw\Desktop\checkFileAge.ps1:10 char:25
+             $out2csv | add-member <<<<  -MemberType NoteProperty -Name FileName -Value $i.fullname
    + CategoryInfo          : InvalidOperation: (@{FileName=C:\u...012 9:33:46 AM}:PSObject) [Add-Member], InvalidOperationException
    + FullyQualifiedErrorId : MemberAlreadyExists,Microsoft.PowerShell.Commands.AddMemberCommand

试试这样的。这是一个更规范的PowerShell

$ext = '*.doc', '*.xls',...
Get-ChildItem C:\Users -r -inc $ext | 
    Where {$_.LastAccessTime -lt [DateTime]::Now.AddMonths(-1)} |
    Select FullName, LastAccessTime |
    Export-Csv -NoTypeInformation -Force C:\FileAccessInformation.csv

是否可以将全名放入变量中,以便我可以将其与另一个函数一起使用?您可以在Where cmdlet之后将Foreach插入管道中,例如
Where…|Foreach{$fn=$\.FullName;在这里执行任务,不输出;$\}\…
注意,在Foreach的末尾,我输出了管道对象,以便可以在管道中进一步处理它。
$ext = '*.doc', '*.xls',...
Get-ChildItem C:\Users -r -inc $ext | 
    Where {$_.LastAccessTime -lt [DateTime]::Now.AddMonths(-1)} |
    Select FullName, LastAccessTime |
    Export-Csv -NoTypeInformation -Force C:\FileAccessInformation.csv