我有这个奇妙的脚本:
gci -Recurse| where {$_.LastWriteTime -gt (Get-Date).AddDays(-45)}| group Extension -NoElement
输出是:
4352 .JPG 2352 .doc 2135 .pdf 1811 .xls 1472 857 .pub 732 .xlsx 565 .docx 66 .rtf 64 .lnk 63 .ppt 61 .url 41 .png 38 .xml 28 .htm 27 .msg
我想要的是同一个脚本在当前目录的每个目录上运行(非recursion)。 例如,如果我在目录c:\test
,并且该目录作为文件夹alex
, liza
和harry
,那么我希望将这个脚本应用于c:\test\alex
, c:\test\liza
, c:\test\harry
我想要的输出是:
4352 .JPG directory name 2352 .doc directory name 2135 .pdf directory name 1811 .xls directory name 1472 directory name 857 .pub directory name 732 .xlsx directory name 565 .docx directory name
我怎样才能修改上面的脚本来为每个目录做这个并追加目录名?
尝试这个
Get-ChildItem c:\test | Where-Object {$_.PSIsContainer} | ForEach-Object{ $folder = $_.FullName Get-ChildItem $_.FullName -Recurse | Where-Object {$_.LastWriteTime -gt (Get-Date).AddDays(-45)} | Group-Object Extension -NoElement | Select-Object Name,Count,@{n='Directory';e={$folder}} }
格式化的问题? 如果不是,可以按多个属性进行分组。
gci -Recurse| where {$_.LastWriteTime -gt (Get-Date).AddDays(-45)}| group Extension, Directory -NoElement