Quick solution for archiving logs to an EBS volume as a Windows Scheduled Task

Contents of LS.ps1
#Must change policy for Windows to allow the script to run, Run the following powershell command without hashtag
#Set-ExecutionPolicy RemoteSigned

$LogDir = “C:\inetpub\logs\wmsvc\W3SVC1”
$ArchiveDir = “D:\logarchive”
$Olderthan = 7

##Copy Files older than 7 days to Archive Directory
robocopy $LogDir $ArchiveDir /move /e /minage:$Olderthan
##Compress each Log file in the directory into a zip file
dir $ArchiveDir\*.log | ForEach-Object { & “C:\Program Files\7-Zip\7z.exe” a -tzip ($_.Name+”.zip”) $_.Name }
##Need to add code to validate logs were compressed before deleting, delete uncompressed Log Files.
del $ArchiveDir\*.log


1. Create a Log archive Volume in AWS
2. Attach Volume to Instance
3.Make the Volume Available for Use
4.Create a Scheduled Task for the LogArchiving Powershell Script.


Leave a Reply

Your email address will not be published. Required fields are marked *