Link to home
Start Free TrialLog in
Avatar of Ben Hart
Ben HartFlag for United States of America

asked on

Powershell, summarize a txt file?

Not sure of the best method to accomplish this.. but since I love Powershell I'm checking here first.

Scenario: I check the nightly backup job logs every morning, but the task of scrolling through and reading it on the server really sucks.  I can choose to export the reports as html or txt files, so I'm wondering if there's a way using PS, to pull certain information from either file type (I'm assuming txt would be easiest) and place that info into a new files or just return it to the screen.

Like for example:

Differential Backup-WedJob History for Differential Backup-Wed



Job Summary Information
Byte count          : 196,203,196,285 bytesJob rate            : 1,176.26 MB/Min (Byte count of all backup sets divided by Elapsed time for all backup sets)Files               : 23,585Directories         : 155,754Skipped files       : 0Corrupt files       : 0Files in use        : 0Original start time : Wednesday, March 16, 2011 8:00:00 PMJob started         : Wednesday, March 23, 2011 8:00:04 PMJob ended           : Wednesday, March 23, 2011 10:46:58 PMElapsed time        : 02:46:54

            Set Detail Information - Backup \\192.168.1.10\Cubes
Set type               : BackupSet status             : CompletedSet description        : Backup to disk WedResource name          : \\192.168.1.10\CubesLogon account          : System Logon AccountEncryption used        : NoneAgent used                     : YesAdvanced Open File Option used : Microsoft Volume Shadow Copy Service (VSS)


Byte count             : 1,042,936,204 bytesRate                   : 978.00 MB/MinFiles                  : 727Directories            : 25Skipped files          : 0Corrupt files          : 0Files in use           : 0Start time             : Wednesday, March 23, 2011 8:00:24 PMEnd time               : Wednesday, March 23, 2011 8:01:25 PMMedia used             : B2D000057


In this case I'm only interested in getting the following:

 Set Detail Information - Backup \\192.168.1.10\Cubes
Set status             : Completed
Resource name          : \\192.168.1.10\Cubes
Byte count             : 1,042,936,204 bytes
Rate                   : 978.00 MB/Min
Start time             : Wednesday, March 23, 2011 8:00:24 PM
End time               : Wednesday, March 23, 2011 8:01:25 PM


Is this possible?  Or is there a better method to use (i.e. vbscript or even batch)?

Thanks!
Avatar of soostibi
soostibi
Flag of Hungary image

Could you attach a sample file, so that I can see exactly what are the delimiters in it?
Avatar of Ben Hart

ASKER

Soostibi - I have to apologize.  I feel like such the idiot, for whatever reason I've never had a need to look under the reporting options for Backup Exec.  I found so many options that would satisfy what I want to do that it's seriously not funny.

You did spend time trying to help me, Admins is it ok to award him points even though he didn't specifically solve it?
Words can't express how stupid I feel right now.  I had thought that the reporting options would covere what I needed.. however after closer inspection it seems that are not able to pull information from specific instances of backup jobs.  Just the overall.  I'm not sure if that makes sense or not.. like I can generate a report based off the results, transfer rates, status, type.. any number of factors for all job histories.  But not that same info for a single job history.

So I'm back to needing to summarize or truncate the history text file.
But anyway, here is the solution, just for the sake of Power of PowerShell! :-)
Get-Content C:\Differential-Backup-Wed.txt -Encoding unicode | select-string "Set detail information" -Context 5 |
%{
    $h = @{}
    $h."Set Detail Information" = ($_.line -replace "Set Detail Information\s-","") -replace "\s{2,}"," ";
    switch -regex ($_.context.postcontext){        
        "(Set\sstatus)\W+:\s(.+?)Set" {$h.($matches[1])=$matches[2]}
        "(Resource\sname)\W+:\s(.+?)Logon" {$h.($matches[1])=$matches[2]}
        "(Byte\scount)\W+:\s(.+?)Rate" {$h.($matches[1])=$matches[2]}
        "(Rate)\W+:\s(.+?)Files" {$h.($matches[1])=$matches[2]}
        "(Start\stime)\W+:\s(.+?)End\stime" {$h.($matches[1])=$matches[2]}
        "(End\stime)\W+:\s(.+?)(Media|General)" {$h.($matches[1])=$matches[2]}
    }
    New-Object -TypeName psobject -Property $h
}

Open in new window

Geez your good. I bow before you.
Soostibi, what parts would be changed to alter the order of the results?  i.e.

resource name:
byte count:
rate:
start time:
end time:

And how hard would it be to also send the output to a new file?
I'm trying to use this script to learn from so what do the operators in that line represent?

"(Start\stime)\W+:\s(.+?)End\stime" {$h.($matches[1])=$matches[2]}

Start and End are fairly obvious, but the \W+:\s(.+?)..

ASKER CERTIFIED SOLUTION
Avatar of soostibi
soostibi
Flag of Hungary image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial