Powershell to Delete log from the remote Computer Share folder

Below powershell helps to delete log from the remote computer which is older than specific date

$Now = Get-Date
$days = 1
$TargetFolder = "\\servername\Directory1"
$LastWrite = $Now.AddDays(-$days)
$Files = get-childitem $TargetFolder -include *.Log -recurse |Where {$_.LastWriteTime -le "$LastWrite"}
Remove-Item $File

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s