none
Get a report in csv file on files last modified since last 7 days. RRS feed

  • Question

  • Hi all,

    I've created a script which works but it displays results on screen and unfortunately writes nothing to csv file. Any help is much appreciated.

    $dir_to_look="F:\testfolder"    
    $month_backdate=$(Get-Date).AddDays(-7)    
    Get-Childitem $dir_to_look -Recurse | ? { !($_.psiscontainer) -and  $_.LastWriteTime -gt $month_backdate } | % { Write-Host "$($_.LastWriteTime) :: $($_.Fullname) " "$($_.LastWriteTime) :: $($_.Fullname) " } | export-csv -path D:\report.csv

    Monday, July 27, 2015 6:11 PM

Answers

All replies

  • Hi,

    Don't use Write-Host, use Select-Object instead.


    • Proposed as answer by Wizend Monday, July 27, 2015 6:22 PM
    • Marked as answer by Dorofeev Dima Tuesday, July 28, 2015 9:17 AM
    Monday, July 27, 2015 6:17 PM
  • Hi Mike,

    Thank you. I've changed the code to the following:

    $dir_to_look="D:\TestFolder"    
    $month_backdate=$(Get-Date).AddDays(-7)    
    Get-Childitem $dir_to_look -Recurse | ? { !($_.psiscontainer) -and  $_.LastWriteTime -gt $month_backdate } | Select-object LastWriteTime, Fullname | export-csv -path \\sharename\report.csv

    Tuesday, July 28, 2015 9:18 AM