If you want to go off of line count you could Get-Content file.log -tail 720 to get the latest 720 lines, save to a temp file, and overwrite the file.log with the temp file. Probably a more efficient way to do it though. Maybe save to a variable instead.
-Stephen > On Dec 22, 2014, at 10:14 AM, Beardsley, James <[email protected]> > wrote: > > Yeah, the director wants an actual log file. I mentioned the event log > because that would be my preference as well but he differed in opinion. > > From: [email protected] [mailto:[email protected]] > On Behalf Of Gilmanov, Nile > Sent: Monday, December 22, 2014 11:03 AM > To: <[email protected]> > Subject: Re: [mssms] OT: Powershell Rolling/Rotating log file > > Have you considered logging to the event log system. E.g application log? > Rotation can be configured by OS itself, size etc? > > Sent from my iPhone > > On Dec 22, 2014, at 10:59 AM, "Beardsley, James" <[email protected]> > wrote: > > I’ve been searching the web and I’m not having any luck finding an answer so > hoping someone has come across this before. I’m looking for a way to add > logging to my posh script that will only keep 30 days. I’ve found some > functions (like this) that’ll archive a log like SCCM does after 30 days (ie: > rename to .lo_ and create a new .log) but I’d like to have the logging > function continue using the same log file but just delete the older lines > from the bottom and continue adding to the top so it’s a continuous 30 days > at all times. > > Or maybe it’d be easier to measure by the number of lines. My script runs > every hour and logs one line to a log file each time. So a months worth of > logging should be around 720 lines if my math is correct and it could delete > lines over 720 and continue adding to the top. > > Is that even possible? > > Thanks, > James > > Confidentiality Notice: This e-mail is intended only for the addressee named > above. It contains information that is privileged, confidential or otherwise > protected from use and disclosure. If you are not the intended recipient, you > are hereby notified that any review, disclosure, copying, or dissemination of > this transmission, or taking of any action in reliance on its contents, or > other use is strictly prohibited. If you have received this transmission in > error, please reply to the sender listed above immediately and permanently > delete this message from your inbox. Thank you for your cooperation. > > > > Confidentiality Notice: This e-mail is intended only for the addressee named > above. It contains information that is privileged, confidential or otherwise > protected from use and disclosure. If you are not the intended recipient, you > are hereby notified that any review, disclosure, copying, or dissemination of > this transmission, or taking of any action in reliance on its contents, or > other use is strictly prohibited. If you have received this transmission in > error, please reply to the sender listed above immediately and permanently > delete this message from your inbox. Thank you for your cooperation. > >

