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 $$<thread=8928 (0x22E0
I simply just want to pull out "Backup completed - Mon Nov 23 22:30:23 2015" (ignore the date, just testing!).
So i came up with this:
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 ?
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?
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"
(Get-Content .\file.log) -match "(?'line'Backup .* \d{4})" ; $Matches['line']
# Result: True
# Backup completed – Mon Nov 23 22:30:23 2015
Thanks Random, I shall give it ago. Will it extract just “Backup completed – Mon Nov 23 22:30:23 2015” ?
Yes, it should. My previous post displays the results.
Thank you again Random. Could you explain the method you used? Trying to get my head round it. Cheers !