Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 在每个目录上执行相同的脚本_Windows_Powershell_Batch File - Fatal编程技术网

Windows 在每个目录上执行相同的脚本

Windows 在每个目录上执行相同的脚本,windows,powershell,batch-file,Windows,Powershell,Batch File,我有一个精彩的剧本: 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

我有一个精彩的剧本:

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
我希望在当前目录的每个目录上运行相同的脚本(非递归)。例如,如果我在目录
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

如何修改上述脚本以对每个目录执行此操作并附加目录名?

格式是否重要?如果没有,则可以按多个属性分组

gci -Recurse| 
    where {$_.LastWriteTime -gt (Get-Date).AddDays(-45)}|
    group Extension, Directory -NoElement
试试这个

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}}
}

非常感谢。我认为它不起作用。我认为它只返回每个目录的前3-5个结果这是输出结果的样子2.xlsx,\\kslfile\prope。。。1.docx,\\kslfile\prope。。。2.xlsx,\\kslfile\prope。。。2.xls,\\kslfile\property。。。2.pdf,\\kslfile\property。。。3.xls,\\kslfile\property。。。1.xls,\\kslfile\property。。。1.xls,\\kslfile\property。。。1.tmp,\\kslfile\property。。。1.文件,\\kslfile\property。。。2.xls,\\kslfile\property。。。1.文件,\\kslfile\property。。。5.发布,\\kslfile\property。。。2.xlsx,\\kslfile\prope。。。8.xls,\\kslfile\property。。。1.xls,\\kslfile\property。。。3.xls,\\kslfile\property…对不起,我最近不在。是目录名在显示器上被截断的问题,还是每个目录都应该有更高的扩展计数?PS Z:\>Get ChildItem Z:| Where Object{$\u.PSIsContainer}| ForEach Object{$folder=$\u.FullName Get ChildItem$\u.FullN ame-Recurse | Where Object{$\u.LastWriteTime-gt(Get Date).AddDays(-45)}|组对象扩展名-NoElement | Select-Object Name,Count,@{n='Directory';e={$folder}}}表达式或语句中意外的标记“Get ChildItem”。在第1行char:104+Get ChildItem z:| Where Object{$\ PSIsContainer}| ForEach Object{$folder=$\ FullNameGet ChildItem看起来在'$\ Full Name'中有一个空格,请将其删除,然后重试。