Question

I would like to pass multiple directories, then get a count of how many files were created yesterday in each directory.

This is what I have cobbled together so far:

$DirNames = @('d:\Work\Test1','d:\Work\Test2')

Get-ChildItem $DirNames | Where-Object { $_.CreationTime -ge (get-date).addDays(-1) }  | 
    Group {$_.LastWriteTime.ToString("yyyy-MM-dd")} | Sort Name -Desc | 
    Format-Table Name,Count -auto

Current Output:

Name       Count
----       -----
2014-03-25     4

It works fine for one directory, but I'm get confused how to show the the directory name in the output listing. The above count is for both directories, what I would like to see is:

Desired Output:

Directory      Date          Count
------------   ----------    -----
D:\Work\Test1  2014-03-25     2
D:\Work\Test2  2014-03-25     2
Était-ce utile?

La solution

try this:

ls $env:temp| group {$_.lastwritetime.tostring('yyyy-MM-dd')} | 
      ft name,count,@{
       'n' = 'Directory'; 
       'e' = { $_ |select -expa group | select -first 1 -expa psparentpath | Convert-Path }
      }

or you can use new pipelinevariable parameter with version 4

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top