Copy of files

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

Try:

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

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

Thanks all. Tried & it worked.

-Kalyan