Powershell script for files housekeeping

Skumar_CCSA used Ask the Experts™
#Requires -version 3.0
$ScriptPath = $(Split-Path -Parent $MyInvocation.MyCommand.Definition)
#Log Timestamp
$logdate=Get-Date -Format ddMMyyyy_HHmmss
$Logfile = "E:\Logs\FileProcessing_$logdate.txt"
function LogWrite ([string]$logstring)
   Add-content $Logfile -value $logstring
#Zip Files and move to backup folder

I am want to build script which will do housekeeping of logs, archive folder and log activity if any file deleted then mention the file name deleted and similaly if log file deleted then log it what files deleted.
if no files to delete for day then mention in the log file no files to delete.
Backup folder archive data should have 7 years, more then 7 years should do rotation (older files to delete and new files to keep).
Backup folder 7 years files to keep, after that older archive files to delete and newer archive file to keep it.
Log folder 1 years logs to keep, after that older log files to delete and newer log file to keep it.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Shaun VermaakSenior Consultant
Awarded 2017
Distinguished Expert 2018

You can if you want, use my CircularLogArchiver tool
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log files in cases where systems do not support circular logging or where circular logging is not enabled


I searched in expert exchange got some idea to do powershell scripting...eventually i noticed above link got it and solved the script work,.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial