-1

My current output to the command

Get-Content -Path $logFilePath

is the following:

Transcript started, output file is \\<path>\

7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21

Open archive: \\<path>\<archive>.zip
--
Path = \\<path>\<archive>.zip
Type = zip
Physical Size = 2543

Scanning the drive:
6 folders, 9 files, 9757 bytes (10 KiB)

Creating archive: \\<path>\<archive>.zip

Add new data to archive: 0 files, 0 bytes


Files read from disk: 0
Archive size: 22 bytes (1 KiB)
Everything is Ok

What is the best way to filter the output, so that it looks something like this

7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21

    New Data Added: 0 files
    New Data Size:  0 bytes
    Archive size after new backup: 22 bytes (1 KiB)

All Help is appreciated - Tortellini

  • Transcript by design outputs everything as if you were sat running the script at a console. If you want a more limited log, it's more efficient to make your own than to go blocking all console output. – Scepticalist Mar 23 '21 at 15:01
  • The Google search "Powershell parse text" has some interesting results. – WaitingForGuacamole Mar 23 '21 at 15:30

1 Answers1

0

Provided your source log retains the same structure the following should give you what you want.

$content = (get-content 'C:\test\New Text Document.txt').Split("`n")
$row15 = (($test[15].Split(':'))[1].Split(',')).Trim()
$NDA = $row15[0]
$NDS = $row15[1]
$NAS = (($test[19].Split(':'))[1]).Trim()
$output = "$($test[2])`r`n`r`n`t`tNew Data Added: $NDA`r`n`t`tNew Data Size:  $NDS`r`n`t`tArchive size after new backup: $NAS"

It's basically a hack and chop job on the content because the structure allowed it. It gets the content rows as an array. From there you can extract the relevant data from the array elements and clean it up before creating a new output string.

You could go down the Regex route to match the data you want and extract it that way but Regex always gives me a headache.

It would be interesting to see how the above compares with what you tried. I'm sure there are many routes to the required outcome and maybe your ideas just needed a little refining.

Tony W
  • 58
  • 6