Powershell report to csv all files modified in last month -


i'm write ps script report in csv of files modified within last month. i've tried 2 options first doesn't write report file , showing results on screen , second nothing. appreciated.

$dir_to_look="d:\testfolder"     $month_backdate=$(get-date).adddays(-1)     get-childitem $dir_to_look -recurse | where-object {!($_.psiscontainer)} | { $_.lastwritetime -gt $month_backdate } | foreach {  write-host "$($_.lastwritetime) :: $($_.fullname) "  } | export-csv -path \\share\filename.csv 

here second one:

 function get-oldfiles {  param($date)  $folders = get-childitem “d:\testfolder” -recurse | where-object {$_.psiscontainer -eq $true}  foreach ($folder in $folders) {      $oldfiles = dir $folder.fullname *.* | where-object {$_.lastwritetime -le $date}      if ($oldfiles.count) {          [float]$totalsize = ($oldfiles | measure-object -sum length).sum / 1kb          $data = @{‘folder’=$folder.fullname;’count’=$oldfiles.count;’size(kb)’=$totalsize}         new-object -type psobject -prop $data         }     } } get-oldfiles ’dd/mm/yyyy′ | export-csv \\sharename\file.csv -notypeinformation 

where dd/mm/yyyy - date want specify each report.

the problem first script powershell returns last statement inside loop, last statement write-host returns nothing outputs console. fix below:

$dir_to_look="d:\testfolder"     $month_backdate=$(get-date).adddays(-1)     get-childitem $dir_to_look -recurse | ? {   !($_.psiscontainer) -and  $_.lastwritetime -gt $month_backdate } | % {    write-host "$($_.lastwritetime) :: $($_.fullname) "     "$($_.lastwritetime) :: $($_.fullname) " } | set-content -path \\share\filename.csv 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -