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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With