Copy of files

Tagged: 

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Venkata Kalyan Venkata Kalyan 5 months, 3 weeks ago.

  • Author
    Posts
  • #42675
    Profile photo of Venkata Kalyan
    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
    Profile photo of Chris Bakker
    Chris Bakker
    Participant

    Try:

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

  • #42710
    Profile photo of random commandline
    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
    Profile photo of Venkata Kalyan
    Venkata Kalyan
    Participant

    Thanks all. Tried & it worked.

    -Kalyan

You must be logged in to reply to this topic.