对每个目录执行相同的脚本 [英] performing the same script on every directory

查看:111
本文介绍了对每个目录执行相同的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个精彩的剧本:

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:\\测试,而目录文件夹亚历丽莎哈里,那么我想这个脚本应用于 C:\\测试\\亚历 C:\\测试\\丽莎 C:\\测试\\哈里

what I would like is this same script to be run on every directory of the current directory (non recursive). for example if i am in directory c:\test, and that directory as the folder alex, liza, and harry, then i want this script to be applied to 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

如何修改上面的脚本,为每个目录做到这一点,追加目录名?

How can I modify the above script to do this for every directory and append the 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}}
}

这篇关于对每个目录执行相同的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆