Copy of files

Welcome Forums General PowerShell Q&A Copy of files

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
2 years, 6 months ago.

  • Author
    Posts
  • #42675

    Participant
    Points: 11
    Rank: Member

    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

    Participant
    Points: 1
    Rank: Member

    Try:

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

  • #42710

    Participant
    Points: 10
    Rank: Member

    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

    Participant
    Points: 11
    Rank: Member

    Thanks all. Tried & it worked.

    -Kalyan

The topic ‘Copy of files’ is closed to new replies.