Author Posts

June 13, 2016 at 5:52 am

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

June 13, 2016 at 9:22 am

Try:

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

June 13, 2016 at 1:23 pm

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

June 14, 2016 at 4:39 am

Thanks all. Tried & it worked.

-Kalyan