1

I'm writing a script which displays the last 7 backups of my server. The scripts outputs the following: TimeCreated, Level, ID, Message,Size in a html table.

my script:

$lastsevendays = (get-date) - (new-timespan -day 7)
$MyObject = Get-WinEvent -FilterHashTable @{LogName='Microsoft-Windows-Backup'; StartTime=$lastsevendays}
$BackupSize = @{ Name = "BackupSize"; Expression = { (($objFSO.GetFolder("C:\Users\LaBackup").Size) / 1MB) } }


$MyObject |
        Select 'TimeCreated', 'LevelDisplayName','ID', 'Message', $BackupSize |
        ConvertTo-HTML -Head $Header |
        Out-file C:\Users\script.htm

I want the script to run everyday and automatically remove backups row which date back from more than 7 seven.

I think i'm supposed to select row which have "Date" less or equal than seven days ago, and delete them to add more recent row.

I have no idea how i could do this as, ConvertTo-HTML seems to regenerate a whole table each time it's called.

Some ideas??

thanks in advance

1 Answer 1

0

Give this a try:

Get-WinEvent -LogName Microsoft-Windows-Backup | Where-Object -FilterScript { $_.TimeCreated -gt [DateTime]::Now.AddDays(-7); }

This uses the Where-Object cmdlet to filter events that are older than 7 days in the Microsoft-Windows-Backup log.

EDIT

I guess I misunderstood what you were looking for. All I did was change the -lt operator to -gt.

1
  • Thanks, but it goes from 03/21/2014 to 08/03/2012. I just need to get the last 7 days that is to say from 03/29/2014 to 03/22/2014 and so on... I want the oldest row to be replaced with a new one Mar 29, 2014 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.