Powershell script to logrotate logs

Question:

Ok.So I want to write a PowerShell script that simulates(sort of) the LogRotate option found in Linux.For one single file:no problem.But I want it to work for all the file INSIDE a folder.But…It doesn’t work…at all.I tried doing it with foreach-object but it still doesn’t work.I’m new to PowerShell programming,so you’ll have to excuse me if my script doesn’t look so clean.
Here it is:

Answer:

You needed to check the file size of each file inside your foreach as LotPings mentioned, and as BenH commented, inside the foreach you need to use $_ to access the current object that is being accessed.

This script worked for me without any errors.

Source:

Powershell script to logrotate logs by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply