ThomasG ThomasG - 1 year ago 98
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.

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download