My powershell script is supposed to do the following:
-
Read the data from the newest log file in the directory
-
Output only the relevant data in an output file on my desktop.
At the moment, i get the entire line everytime the word "lobbyid" appears in the document.
My code:
Get-ChildItem -Path "C:\Program Files\Example\logs" |Sort-Object LastAccessTime -Descending | Select-Object -First 1 | Select-String –Pattern "lobbyid"| Select Filename,Line | Format-Table -wrap | Out-File $env:USERPROFILE\Desktop\output.txt -append'
On a log file containing
XXXXXXXXXXXXXXXXXXXXX
{"seqid":5,"lobbyid":"9A74E75D-2BCB-4750-BF3A-87BB4992DC2D","mm":{"status":7}
{"seqid":12,"lobbyid":"CFDAAA9C-F973-40CF-A477-143A5810061D","mm":{"status":10}
YYYYYYYYYYYYYYYYYYYYY
I get
{"seqid":5,"lobbyid":"9A74E75D-2BCB-4750-BF3A-87BB4992DC2D","mm":{"status":7}
{"seqid":12,"lobbyid":"CFDAAA9C-F973-40CF-A477-143A5810061D","mm":{"status":10}
But I would like the output
Line 1: 9A74E75D-2BCB-4750-BF3A-87BB4992DC2D
Line 2: CFDAAA9C-F973-40CF-A477-143A5810061D
Or something similar. I tried replacing "lobbyid" with 'lobbyid(.*?)mm' But that gave the same output.
Aucun commentaire:
Enregistrer un commentaire