Quantcast
Channel: Tech Support Guy
Viewing all articles
Browse latest Browse all 29110

Powershell - HTML output of newest files

$
0
0
Hi,

I've put off learning Powershell for too long and now I have a need to know it, my basic knowledge isn't enough! Any help gratefully received.

I've got a couple of SQL Servers and a few too many SQL Express Servers which I'm backing up. The backup file is held on the local machine. We have a central repository which gets backed up to tape so I have a batch file which copies the backups from the local machines to the central repository. In the central repository each server has a folder where the backup files are stored until a "forfiles" retention statement removes the oldest.

What I've been trying to make is a simple report which shows the newest file in each folder, and highlights any which are older than 24 hours (i.e. a backup has failed).

Using a TechNet article (http://technet.microsoft.com/en-us/l.../ff730936.aspx) I've got the following:

Code:

$a = "<style>"
$a = $a + "BODY{background-color:peachpuff;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}"
$a = $a + "</style>"

get-childitem -path "\\<central repo>\SQLBackup" -recurse | select name, lastwritetime | where {($_.LastWriteTime -lt (Get-Date).AddDays(-1))} | ConvertTo-HTML -head $a -body "<H2>Check the dates</H2>" | Out-File "test.htm"

This is ok to a point but I'm looking for any pointers people have on how to improve in the following areas:
  • Highlight the line in the table, or the individual date cell, if the lastWriteTime is older than 24 hours
  • Only pull in the newest file from the sub-directories, not just the ones from the last 24 hours (so if files are older than 24 hours they still show and therefore trigger the highlighting above

I'm going to keep playing around with it to work out some of the issues but as I said, any help or advice or articles to read would be welcome.

Cheers
Andrew

Viewing all articles
Browse latest Browse all 29110

Trending Articles