Export-csv creates an empty CSV file

This is my first PowerShell script and I have looked through a lot of topics but can't find what is wrong. I am trying to check if files with two extensions are created in the today folder and output the filename and date to a csv file.

My code:

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 is created, but no data fits into it, even though the information I need is displayed in the PowerShell window when the code runs.

+3


source to share


2 answers


You are missing a pipeline |

between the cmdlet Where-Object

and Select-Object

:



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

      

+1


source


I found the missing pipe after .Date}



+1


source







All Articles