ThomasG ThomasG - 7 months ago 49
PowerShell Question

How can you use powershell to document deleting logs?

I am new to powershell and I am just curious if when I use a script to delete logs is there a command that will gather how many logs were deleted and the amount of space that was cleared (memory wise) after deleting logs and put it into a text file? So I can just log in and view the document and know exactly how many logs were deleted and how much memory is now available after deleting those logs.


Here's something that might get you going. It gets a list of .log files, deletes them and then prints some info on them (because the info has been already gathered).

$files = ls *.log
foreach ($file in $files) {
    del $file
    "Deleted: $($file.Name) Size: $($file.Length)" | set-content .\deletelog.txt