Copy of files

This topic contains 3 replies, has 3 voices, and was last updated by  Venkata Kalyan 1 year, 5 months ago.

  • Author
    Posts
  • #42675

    Venkata Kalyan
    Participant

    Hi,
    I wrote a script which will copy the latest log from \\ihsfs09\Weblogs\windows\dsfprdapp711 and place it C:\Opscripts\Kalyan\Staples_Logs_for_Slow_Service\dsfprdapp711

    $dir = "\\ihsfs09\Weblogs\windows\dsfprdapp711"
    $latest = Get-ChildItem -Path $dir | Sort-Object LastAccessTime -Descending | Select-Object -First 1 | cpi -dest C:\Opscripts\Kalyan\Staples_Logs_for_Slow_Service\dsfprdapp711
    $latest.name

    I am trying to get 7days logs from \\ihsfs09\Weblogs\windows\dsfprdapp711 and place it in C:\Opscripts\Kalyan\Staples_Logs_for_Slow_Service\dsfprdapp711

    But could not get it, can some one please help on this.

    -Kalyan

  • #42680

    Chris Bakker
    Participant

    Try:

    Get-ChildItem -Path $dir | Sort-Object LastAccessTime -Descending | Select-Object -First 7

  • #42710

    random commandline
    Participant

    This will copy all files accessed in the past 7 days.

    $source = "\\ihsfs09\Weblogs\windows\dsfprdapp711"
    $dest = "C:\Opscripts\Kalyan\Staples_Logs_for_Slow_Service\dsfprdapp711"
    $pastdate = (Get-Date).AddDays(-7)
    
    Get-ChildItem -Path $source -File | Where-Object {$_.LastAccessTime -ge $pastdate} |
    Copy-Item -Destination $dest
    
  • #42836

    Venkata Kalyan
    Participant

    Thanks all. Tried & it worked.

    -Kalyan

You must be logged in to reply to this topic.