Assuming you are only adding one line at a time, and that the log file isn’t 
huge, then something like this should do it……

$path = "c:\Something.log"

$file = Get-Content $path -ReadCount 0
Set-Content $path -Value ($file | Select-Object -First ($file.count-1))

Matt


From: [email protected] [mailto:[email protected]] On 
Behalf Of Stephen Leuthold
Sent: 22 December 2014 17:12
To: [email protected]
Subject: Re: [mssms] OT: Powershell Rolling/Rotating log file

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]<mailto:[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]> 
[mailto:[email protected]] On Behalf Of Gilmanov, Nile
Sent: Monday, December 22, 2014 11:03 AM
To: <[email protected]<mailto:[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]<mailto:[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<http://blogs.msdn.com/b/rslaten/archive/2014/07/28/logging-in-cmtrace-format-from-powershell.aspx>)
 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.
---------------------------------------------------------------------------------------
Information in this message is sent in confidence and is intended only for
the use of the individual or entity to whom it is addressed.  If you are not
the intended recipient, any use, distribution or copying of the information
is strictly forbidden.  Please notify the sender immediately by return email
or telephone 01823 721400. If you received this email in error please delete 
it and any copies of it from your system.

Viridor Waste Management Limited
Registered Office: Peninsula House, Rydon Lane, Exeter EX2 7HR
Registered in England No. 575069
---------------------------------------------------------------------------------------

Reply via email to