Reputation: 181
This is my first PowerShell script and I've went over lots of topics but can't seem to find what is wrong. I'm trying to see if files with two extensions are created in a folder 'today' and output filename and date into a csv file.
My code is:
Get-ChildItem 'PATH' -recurse -include @("*.txt*","*.txt.gz") | Where-Object { $_.CreationTime -gt (Get-Date).Date } Select-Object FullName, CreationTime, @{Name="Mbytes";Expression={$_.Length/1Kb}}, @{Name="Age";Expression={(((Get-Date) - $_.CreationTime).Days)}} | Export-Csv -path 'PATH' -Append
The file gets created, but no data is put into it, even if the info I need is displayed in the PowerShell window when running the code.
Upvotes: 3
Views: 1673
Reputation: 59031
You are missing a |
pipeline between the Where-Object
and the Select-Object
cmdlet:
Get-ChildItem 'PATH' -recurse -include @("*.txt*","*.txt.gz") |
Where-Object { $_.CreationTime -gt (Get-Date).Date } |
Select-Object FullName,
CreationTime,
@{Name="Mbytes";Expression={$_.Length/1Kb}},
@{Name="Age";Expression={(((Get-Date) - $_.CreationTime).Days)}} |
Export-Csv -path 'PATH' -Append
Upvotes: 1