Author Posts

March 14, 2016 at 6:43 am

Hi,

I'm writing a backup copy script for SCCM to copy the backup files to another server for redundancy purposes.

This is the example line:
Backup completed – Mon Nov 23 22:30:23 2015 $$ This is just to test on the one line, but i will look for the last successful date $a = get-content "E:\SCCM_Backup\AACBackup\smsbkup.log" | where { $_ -like "*Backup completed - Mon Nov 23 22:30:23 2015*" } Create the pattern

[regex]$pattern = "\$\$< (1[0-2]|0[1-9]|[1-9])-"

Finally select the first line

$a[0]

This does give me the desired result but doesn't feel right. Can someone point me in the right direction please ?

March 14, 2016 at 7:44 am

The \$\$ in the regex is searching for $$, and thats not in your backup line.
So what in the logfile, what are you trying to match?

March 14, 2016 at 8:01 am

It keeps purging my string.

Backup completed – Mon Nov 23 22:30:23 2015 $$ SMS_SITE_BACKUP11-23-2015 22:30:23.907+00thread=8928 (0x22E0)

I've had to remove < as it removes them. Its an SCCM log file. I just want to extract "Backup completed – Mon Nov 23 22:30:23 2015"

March 14, 2016 at 9:02 am

(Get-Content .\file.log) -match "(?'line'Backup .* \d{4})" ; $Matches['line']
# Result: True
# Backup completed – Mon Nov 23 22:30:23 2015

March 14, 2016 at 10:37 am

Thanks Random, I shall give it ago. Will it extract just "Backup completed – Mon Nov 23 22:30:23 2015" ?

March 14, 2016 at 11:59 am

Yes, it should. My previous post displays the results.

March 14, 2016 at 12:53 pm

Thank you again Random. Could you explain the method you used? Trying to get my head round it. Cheers !