-4

i need some regex help to parse out powershell objects from log file.

Looking to make a powershell object with these note properties:

ACVS_D = Date
ACVS_TI = Info
ACVS_C = Name
ACVS_M = Message

Any help would be greatly appreciated! thank you!

Example of xml in .log file:

<ACVS_T>
    <ACVS_D>12/23/2016 03:25:14.324</ACVS_D>
    <ACVS_TI>db818c30-cdb9-4482-9b51-8f6aad8e914c,C?Cure Reports Server Component,svc-ccureMAS</ACVS_TI>
    <ACVS_C>CrossFireWindowsService</ACVS_C>
    <ACVS_S>SoftwareHouse.CrossFire.Server.Shared.CrossFireWindowsService.TraceMessage( String methodName, String message )
</ACVS_S>
    <ACVS_M>
        CrossFireReportServer.ReconnectToServer() connected at 12/23/2016 3:25:14 AM
    </ACVS_M>
<ACVS_ST>

    </ACVS_ST>
</ACVS_T>
<ACVS_T>
    <ACVS_D>12/23/2016 03:25:14.324</ACVS_D>
    <ACVS_TI>6af6dfab-c890-42c5-acd2-a9520e9742da,C?Cure Reports Server Component,svc-ccureMAS</ACVS_TI>
    <ACVS_C>CrossFireWindowsService</ACVS_C>
    <ACVS_S>SoftwareHouse.CrossFire.Server.Shared.CrossFireWindowsService.TraceMessage( String methodName, String message )
</ACVS_S>
    <ACVS_M>
        CrossFireReportServer.ReconnectToServer() connected at 12/23/2016 3:25:14 AM
    </ACVS_M>
<ACVS_ST>

    </ACVS_ST>
</ACVS_T>
2
  • 3
    Don't do it with regexes. Commented Dec 23, 2016 at 21:22
  • 2
    Select-Xml -Path Log.xml -XPath 'RootNodeHere/ACVS_T' | ForEach { $_.Node ... } Commented Dec 24, 2016 at 0:27

1 Answer 1

0

I wouldn't suggest using regex unless it is a very big file. You need a regex search string like this (?<=<ACVS_T>)((.|\n)*)(?=<\/ACVS_T>) please adjust for each part you need.

You can just add a root node and interpret this as a XML file. As the example below:

$File = "PathToFile"

$XML =  [XML]("<Root>" + (Get-Content -Path $File) + "</Root>" )

$XML.Root.ACVS_T | ForEach-Object {
    $Obj = '' | Select-Object -Property ACVS_D, ACVS_TI, ACVS_C, ACVS_S, ACVS_M, ACVS_ST
   $Obj.ACVS_D = $_.ACVS_D
   $Obj.ACVS_ST = $_.ACVS_ST
   $Obj.ACVS_C = $_.ACVS_C
   $Obj.ACVS_S = $_.ACVS_S
   $Obj.ACVS_M = $_.ACVS_M
   $Obj.ACVS_ST = $_.ACVS_ST
   $Obj
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks that really helped!
Could you please accept this as te answer?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.