Search code examples
xmlpowershellcsvsplitnested-loops

powershell - Nested FORLOOPs to split string and replace a portion of the string and Remove everything after string


I have an XML file that I'm converting into a CSV

[xml]$XML = Get-Content .\myconfigs.xml
$xml.Property1.Property2 | Export-CSV myconfigs.csv

The above two lines works perfectly to import the XML, parse past the first couple of layers that i dont need and export it to an CSV.

The CSV has the following headers: The CSV file has: name,description,rule,owner,window,lastupdated

Ultimately I want to have only the name, description and rule values, but I need to manipulate the NAME column slightly, and the DESCRIPTION column heavily. The RULE column is formatted perfectly as it is.

To manipulate the data contained in the CSV, I suppose it could be done within the XML, but Im not sure how, so i was trying to do it in stages.

First I need to split the data in the NAME column, which I can do here. The data is: "A bunch of text.something.XXX.a whole bunch more text" where XXX is the target. I do that here, however if i try and export it as a CSV again, it errors because it says InputObject is null, so I Set-Content instead:

Import-Csv "myconfigs.csv" -Header name,description,rule |
    % {$_.name.Split('.')[2]} |
    Set-Content "name_results.csv"

And thats where I run into my first problem. While it splits the data in the NAME column appropriately, it only writes that column, with no header, to the new CSV file, which breaks this from being one file, but I figured worst case scenario I could just copy the columns from each file and slap them into a spreadsheet, save as csv. done, but i run into more challenges below.

I need to do another, massive split in the DESCRIPTION column so i go back to the results1.csv fileand do the following, the data is too long for me to want to replicate here, just suffice to say this DOES work. And I get the correct value from the array, but again I cant Export-CSV so I Set-Content

Import-Csv "results1.csv" -Header name,description,rule |
    % {$_.description.Split('""')[21]} |
    Set-Content "desc_results.csv"

Now, I need to further manipulate the DESCRIPTION field and, because ive imported a CSV then Set-Content, but it writes no header, but what I'm doing is replacing the word "Five" with the word "One".

Get-Content "descresults.csv" |
    % {$_ -replace "Five", "One"} |
    Set-Content "oneresults.csv"

The problem with setting the content like this is that due to the missing header it surrounds my output with @{all my results}

I then need to do another replace on the DESCRIPTION column, further compounding the @{@{}}

Get-Content "oneresults.csv" |
    % {$_ -replace "P2D", "PT3H"} |
    Set-Content "PT3Hresults.csv"

I need to After that, i need to trim everything after the string "P0D" in the results here in what should be the DESCRIPTION column, but i tried figuring that out and am failing. I saw a cool way to do it but havent been able to get it to work in my use case, something called a positive reverse look up

$input -replace "(?<=P0D).*"
Set-Content trim.csv

So now at this point, (if i could get this to work) I would have: the desired results of my NAME column in nameresults.csv, the desired results of the DESCRIPTION field in trim.csv (though its got @{@{@{allmydata}}}, but if that's the worst i have to clean up, that's easy, and the desired results from the RULE column way back in the original myconfig.csv

I'd like to discard all of the other columns in the file (owner,window,lastupdated) or just not import them to begin with.

NOTE: everything above this note has to do with my trials. the delimiters mentioned are incorrect if doing the parsing through the XML rather than in the CSV, please see below

Acceptance Criteria: Script should extract the NAME, DESCRIPTION, RULES data from the XML file and export it into the CSV file

Each line in the NAME column needs to have the 3 character code in the third place in the array[2], period(.) delimited, and written to the NAME column as the only data in this column in the final output file.

Each line in the DESCRIPTION column needs to have the 28th place in the array[27], double-double quote("") delimited, extracted from the data, then the string "Five" replaced with the string "One", the string "P2D" replaced with the string PT3H, and then everything after the string =P0D trimmed from the end of the string and written to the DESCRIPTION column with no leading or trailing characters in the final output file.

Each line in the RULE, needs to be copied/written to the RULE column in the final output file.

Im open to the splitting/replacing being done either at the XML level, prior to exporting to the CSV or after its in the CSV format, either is fine so long as the end it is a CSV meeting the above criteria. Headers would be nice, but arent necessary.

I got so close but I cant get all of the columns in the CSV file, I keep getting the @{} appended/prepended to my data, or the description line trimmed. Its 5am and I really need to sleep so im hoping someone can help me out before I wake

Thanks in advance for any assistance.

Well. the xml is pretty massive. I'll only share one grouping, but it iterates with the changes i indicated. Due to the nature of the content, I had to go through and replace most of the actual data with Lorem Ipsum text and gibberish. I left all of the format and special characters the same, and did a ReplaceAll for all of the changes I made so that they remain consistent throughout, as we're already as deep into the XML as there is (there are no XML properties within the property) the actual words here should not matter, with exception of those that I need to replace.

Also, since StackOverFlow doesnt like me trying to format within the codeblock or inline, ive broken out the section i need, just know there are no spaces or special characters between the end of the codeblock, beginning of the URL, or between the end of the URL and the beginning of the next codeblock. Treat it as if it were all one codeblock. Within the part I broke out the FiveMollis becomes OneMollis and the P2D becomes PT3H

<Property1>
  <Property2>
    <name>Lorem ipsum dolor.sit.AAA.amet consectetur adipiscing elit sed do eiusmod tempor</name>
    <description>Dona Nobut Patrim &lt;br&gt; A malesuada eget vitae malesuadaVestibulum - MIL Lacus SVELen Ipsum VEL ut turpis-in-eu et cliff.sed wala: &lt;a href="https://w.lobortis.com/index.php/malesuadaing/senectus/auctor/FD12SLJ1"&gt;malesuadaVestibulum - MIL Lacus SVELen Ipsum&lt;/a&gt;&lt;br&gt;cursus aliquam to malesuada 1 malesuadas &lt;br&gt;&lt;br&gt;&lt;p&gt;&lt;table border="1"&gt;&lt;tr&gt;&lt;td align="center"&gt;&lt;b&gt;Lorem&lt;/b&gt;&lt;/td&gt;&lt;td align="center"&gt;&lt;b&gt;MattisNunc&lt;/b&gt;&lt;/td&gt;&lt;td align="center"&gt;&lt;b&gt;Menus&lt;/b&gt;&lt;/td&gt;&lt;td align="center"&gt;&lt;b&gt;2Aq Grenda&lt;/b&gt;&lt;/td&gt;&lt;td align="center"&gt;&lt;b&gt;24P Grenda&lt;/b&gt;&lt;/td&gt;&lt;td align="center"&gt;&lt;b&gt;Congue&lt;/b&gt;&lt;/td&gt;&lt;td align="center"&gt;&lt;b&gt;Semper&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;aaa&lt;/td&gt;&lt;td&gt;ALL&lt;/td&gt;&lt;td&gt;&lt;a href="https://malesuadapulvinar.lobortis.com/malesuadas/onsonjo?&amp;id=me-sorto-1:malesuadaing.MIL.AAA.Aliquam.malesuadaVestibulum.malesuadaVestibulum - MIL Lacus SVELen Ipsum.amet.PharetraAaBbAaBbAaBbBbAaAaBb.17f9as1dag71a8av169a1"&gt;Tellus&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;a href="https://malesuadapulvinar.lobortis.com/igrenda?&amp;SuscipitNisi1=Scelerisque&amp;DranarSit1=Porta&amp;Mullendisto1=aaa&amp;HabitantGrunpa1=ALL&amp;Habitant1=ALL&amp;ScelerisqueNisi1=malesuadaVestibulum&amp;MattisNunc1=ALL&amp;Cursus1=ALL&amp;MenusCloues1=NONE&amp;Inhedishet1=NONE&amp;Menus1=Tellus&amp;Pursius=OnteHongo&amp;Tats1=p99&amp;ViverraUrna1=millutecond&amp;UltriciesLarbano1=ALL&amp;BeignTellus1=-P14D&amp;EndeligTellus1=-P0D&amp;HendreritLiberoLanto1=5000.0&amp;HinestIdPriste=100&amp;WondeIdPriste=150&amp;DecagearPontas=false&amp;search=suscipitnisi%3DScelerisque%20dontateteste%3D%24Porta%24%20consumenumem%3D%24aaa%24%20maestroguildido%3D%24ALL%24%20masetro%3D%24ALL%24%20scelerisquenisi%3D%24malesuadaVestibulum%24%20MattisNunc%3D%24ALL%24%20consueno%3D%24ALL%24%20Menuseros%3D%24NONE%24%20insisante%3D%24NONE%24%20Menus%3D%24Tellus%24"&gt;&lt;img src="https://malesuadapulvinar.lobortis.com/MIL?Acliqua=GetGrenda&amp;Vitae=2000-01-01&amp;SuscipitNisi1=Scelerisque&amp;DranarSit1=Porta&amp;Mullendisto1=aaa&amp;HabitantGrunpa1=ALL&amp;Habitant1=ALL&amp;ScelerisqueNisi1=malesuadaVestibulum&amp;MattisNunc1=ALL&amp;Cursus1=ALL&amp;MenusCloues1=NONE&amp;Inhedishet1=NONE&amp;Menus1=Tellus&amp;Pursius=OnteHongo&amp;Tats1=p99&amp;ViverraUrna1=millutecond&amp;UltriciesLarbano1=ALL&amp;BeignTellus1=-P14D&amp;EndeligTellus1=-P0D&amp;HendreritLiberoLanto1=5000.0&amp;HinestIdPriste=100&amp;WondeIdPriste=150&amp;DecagearPontas=false&amp;ApeararExsislano=false&amp;ApeararXAxutContedido=false" alt="iGrenda"/&gt;&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;a href="

https://malesuadapulvinar.lobortis.com/igrenda?&SuscipitNisi1=Scelerisque&DranarSit1=Porta&Mullendisto1=aaa&HabitantGrunpa1=ALL&Habitant1=ALL&ScelerisqueNisi1=malesuadaVestibulum&MattisNunc1=ALL&Cursus1=ALL&MenusCloues1=NONE&Inhedishet1=NONE&Menus1=Tellus&Pursius=FiveMollis&Tats1=p99&ViverraUrna1=millutecond&UltriciesLarbano1=ALL&BeignTellus1=-P2D&EndeligTellus1=-P0D

&amp;HendreritLiberoLanto1=5000.0&amp;HinestIdPriste=100&amp;WondeIdPriste=150&amp;DecagearPontas=false&amp;search=suscipitnisi%3DScelerisque%20dontateteste%3D%24Porta%24%20consumenumem%3D%24aaa%24%20maestroguildido%3D%24ALL%24%20masetro%3D%24ALL%24%20scelerisquenisi%3D%24malesuadaVestibulum%24%20MattisNunc%3D%24ALL%24%20consueno%3D%24ALL%24%20Menuseros%3D%24NONE%24%20insisante%3D%24NONE%24%20Menus%3D%24Tellus%24"&gt;&lt;img src="https://malesuadapulvinar.lobortis.com/MIL?Acliqua=GetGrenda&amp;Vitae=2000-01-01&amp;SuscipitNisi1=Scelerisque&amp;DranarSit1=Porta&amp;Mullendisto1=aaa&amp;HabitantGrunpa1=ALL&amp;Habitant1=ALL&amp;ScelerisqueNisi1=malesuadaVestibulum&amp;MattisNunc1=ALL&amp;Cursus1=ALL&amp;MenusCloues1=NONE&amp;Inhedishet1=NONE&amp;Menus1=Tellus&amp;Pursius=FiveMollis&amp;Tats1=p99&amp;ViverraUrna1=millutecond&amp;UltriciesLarbano1=ALL&amp;BeignTellus1=-P2D&amp;EndeligTellus1=-P0D
&amp;HendreritLiberoLanto1=5000.0&amp;HinestIdPriste=100&amp;WondeIdPriste=150&amp;DecagearPontas=false&amp;ApeararExsislano=false&amp;ApeararXAxutContedido=false" alt="iGrenda"/&gt;&lt;/a&gt;&lt;/td&gt;&lt;td&gt;p99 &gt; &lt;b&gt;5000.000000 millutecond&lt;/b&gt; &lt;br&gt;eget &lt;b&gt;3&lt;/b&gt; data points &lt;br&gt;(clear in &lt;b&gt;3&lt;/b&gt; data points)&lt;/td&gt;&lt;td&gt;&lt;a href="https://malesuadapulvinar.lobortis.com/malesuadas/onsonjo?&amp;id=me-sorto-1:malesuadaing.MIL.AAA.Aliquam.malesuadaVestibulum.malesuadaVestibulum - MIL Lacus SVELen Ipsum.amet.PharetraAaBbAaBbAaBbBbAaAaBb.8f94sa9d6846a81sds46d8sf146a83a68sda4g"&gt;&lt;div id="me-sorto-1:malesuadaing.MIL.AAA.Aliquam.malesuadaVestibulum.malesuadaVestibulum - MIL Lacus SVELen Ipsum.amet.PharetraAaBbAaBbAaBbBbAaAaBb.8f94sa9d6846a81sds46d8sf146a83a68sda4g"&gt;Semper...&lt;/div&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;script&gt;onload=changeLink;function changeLink(){contents="";j=0;eget(i=0; i &lt; document.links.length; i++){if(document.links[i].erosNisi == "grendalink"){id = document.links[i].href.split('%2c+')[1];html = document.links[i].innerHTML;document.getElementById(id).innerHTML = html;}}}&lt;/script&gt;</description>
    <alarmRule>AlarmA;</alarmRule>
    <owner>OwnerA</owner>
    <window>10</window>
    <tailWindow>10</tailWindow>
    <lastUpdated>2000-01-01T10:00:00+01:00</lastUpdated>
  </Property2>
</Property1>

Solution

  • You should do all before exporting. Something like this:

    //Here I had in first answer code with generating xml document, but you need just to export it to csv. My bad.

    You can do this:

    This code is if you want to have more control over it and add some other things like checking values and etc...

    *Solution with select-string

    [xml]$xml = Get-Content "myConfigs.txt"
    $results = @()
    foreach ($xmlElement in $xml.Property1.Property2)
    {
        $results += [PSCustomObject]@{
            name = $xmlElement.name.Split(".")[2]
            description =description = $xmlElement.description.Substring(($xmlElement.description | Select-String -Pattern "<a href=" -AllMatches).Matches[3].Index + '<a href=">'.Length) -replace "Five","One" -replace "P2D","PT3H" -replace "(?<=P0D).*"
            alarmRule = $xmlElement.alarmRule
        }
    }
    $results | Export-Csv "myCsv.csv" -Encoding UTF8 -NoTypeInformation
    

    This code is oneliner which is really simple but should do everything what you need.

    [xml]$xml = Get-Content "myConfigs.txt"
    $xml.Property1.Property2 | select @{l="name";e={$_.name.Split('.')[2]}}, @{l="description";e={$_.description.Substring(($_.description | Select-String -Pattern "<a href=" -AllMatches).Matches[3].Index + '<a href=">'.Length) -replace "Five","One" -replace "P2D","PT3H" -replace "(?<=P0D).*"}}, alarmRule | Export-Csv "myCsv.csv" -Encoding UTF8 -NoTypeInformation
    

    *Solution with using Regex class from System.Text.RegularExpressions (it really doesn't matter I'm showing it only because you asked what it means in my code)

    $results = @()
    foreach ($xmlElement in $xml.Property1.Property2)
    {
        $results += [PSCustomObject]@{
            name = $xmlElement.name.Split(".")[2]
            description = $xmlElement.description.Substring([Regex]::Matches($xmlElement.description,"<a href=")[3].Index + '<a href=">'.Length) -replace "Five","One" -replace "P2D","PT3H" -replace "(?<=P0D).*"
            alarmRule = $xmlElement.alarmRule
        }
    }
    

    *Oneliner

    [xml]$xml = Get-Content .\myconfigs.xml
    $xml.Property1.Property2 | select @{l="name";e={$_.name.Split('.')[2]}}, @{l="description";e={$_.description.Substring([Regex]::Matches($_.description,"<a href=")[3].Index + '<a href=">'.Length) -replace "Five","One" -replace "P2D","PT3H" -replace "(?<=P0D).*"}}, alarmRule | Export-Csv "myCsv.csv" -Encoding UTF8 -NoTypeInformation
    

    Source:

    <Property1>
      <Property2>
        <name>Lorem ipsum dolor.sit.AAA.amet consectetur adipiscing elit sed do eiusmod tempor</name>
        <description>Dona Nobut Patrim &lt;br&gt; A malesuada eget vitae malesuadaVestibulum - MIL Lacus SVELen Ipsum VEL ut turpis-in-eu et cliff.sed wala: &lt;a href="https://w.lobortis.com/index.php/malesuadaing/senectus/auctor/FD12SLJ1"&gt;malesuadaVestibulum - MIL Lacus SVELen Ipsum&lt;/a&gt;&lt;br&gt;cursus aliquam to malesuada 1 malesuadas &lt;br&gt;&lt;br&gt;&lt;p&gt;&lt;table border="1"&gt;&lt;tr&gt;&lt;td align="center"&gt;&lt;b&gt;Lorem&lt;/b&gt;&lt;/td&gt;&lt;td align="center"&gt;&lt;b&gt;MattisNunc&lt;/b&gt;&lt;/td&gt;&lt;td align="center"&gt;&lt;b&gt;Menus&lt;/b&gt;&lt;/td&gt;&lt;td align="center"&gt;&lt;b&gt;2Aq Grenda&lt;/b&gt;&lt;/td&gt;&lt;td align="center"&gt;&lt;b&gt;24P Grenda&lt;/b&gt;&lt;/td&gt;&lt;td align="center"&gt;&lt;b&gt;Congue&lt;/b&gt;&lt;/td&gt;&lt;td align="center"&gt;&lt;b&gt;Semper&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;aaa&lt;/td&gt;&lt;td&gt;ALL&lt;/td&gt;&lt;td&gt;&lt;a href="https://malesuadapulvinar.lobortis.com/malesuadas/onsonjo?&amp;id=me-sorto-1:malesuadaing.MIL.AAA.Aliquam.malesuadaVestibulum.malesuadaVestibulum - MIL Lacus SVELen Ipsum.amet.PharetraAaBbAaBbAaBbBbAaAaBb.17f9as1dag71a8av169a1"&gt;Tellus&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;a href="https://malesuadapulvinar.lobortis.com/igrenda?&amp;SuscipitNisi1=Scelerisque&amp;DranarSit1=Porta&amp;Mullendisto1=aaa&amp;HabitantGrunpa1=ALL&amp;Habitant1=ALL&amp;ScelerisqueNisi1=malesuadaVestibulum&amp;MattisNunc1=ALL&amp;Cursus1=ALL&amp;MenusCloues1=NONE&amp;Inhedishet1=NONE&amp;Menus1=Tellus&amp;Pursius=OnteHongo&amp;Tats1=p99&amp;ViverraUrna1=millutecond&amp;UltriciesLarbano1=ALL&amp;BeignTellus1=-P14D&amp;EndeligTellus1=-P0D&amp;HendreritLiberoLanto1=5000.0&amp;HinestIdPriste=100&amp;WondeIdPriste=150&amp;DecagearPontas=false&amp;search=suscipitnisi%3DScelerisque%20dontateteste%3D%24Porta%24%20consumenumem%3D%24aaa%24%20maestroguildido%3D%24ALL%24%20masetro%3D%24ALL%24%20scelerisquenisi%3D%24malesuadaVestibulum%24%20MattisNunc%3D%24ALL%24%20consueno%3D%24ALL%24%20Menuseros%3D%24NONE%24%20insisante%3D%24NONE%24%20Menus%3D%24Tellus%24"&gt;&lt;img src="https://malesuadapulvinar.lobortis.com/MIL?Acliqua=GetGrenda&amp;Vitae=2000-01-01&amp;SuscipitNisi1=Scelerisque&amp;DranarSit1=Porta&amp;Mullendisto1=aaa&amp;HabitantGrunpa1=ALL&amp;Habitant1=ALL&amp;ScelerisqueNisi1=malesuadaVestibulum&amp;MattisNunc1=ALL&amp;Cursus1=ALL&amp;MenusCloues1=NONE&amp;Inhedishet1=NONE&amp;Menus1=Tellus&amp;Pursius=OnteHongo&amp;Tats1=p99&amp;ViverraUrna1=millutecond&amp;UltriciesLarbano1=ALL&amp;BeignTellus1=-P14D&amp;EndeligTellus1=-P0D&amp;HendreritLiberoLanto1=5000.0&amp;HinestIdPriste=100&amp;WondeIdPriste=150&amp;DecagearPontas=false&amp;ApeararExsislano=false&amp;ApeararXAxutContedido=false" alt="iGrenda"/&gt;&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;a href=">https://malesuadapulvinar.lobortis.com/igrenda?&amp;SuscipitNisi1=Scelerisque&amp;DranarSit1=Porta&amp;Mullendisto1=aaa&amp;HabitantGrunpa1=ALL&amp;Habitant1=ALL&amp;ScelerisqueNisi1=malesuadaVestibulum&amp;MattisNunc1=ALL&amp;Cursus1=ALL&amp;MenusCloues1=NONE&amp;Inhedishet1=NONE&amp;Menus1=Tellus&amp;Pursius=FiveMollis&amp;Tats1=p99&amp;ViverraUrna1=millutecond&amp;UltriciesLarbano1=ALL&amp;BeignTellus1=-P2D&amp;EndeligTellus1=-P0D&amp;HendreritLiberoLanto1=5000.0&amp;HinestIdPriste=100&amp;WondeIdPriste=150&amp;DecagearPontas=false&amp;search=suscipitnisi%3DScelerisque%20dontateteste%3D%24Porta%24%20consumenumem%3D%24aaa%24%20maestroguildido%3D%24ALL%24%20masetro%3D%24ALL%24%20scelerisquenisi%3D%24malesuadaVestibulum%24%20MattisNunc%3D%24ALL%24%20consueno%3D%24ALL%24%20Menuseros%3D%24NONE%24%20insisante%3D%24NONE%24%20Menus%3D%24Tellus%24"&gt;&lt;img src="https://malesuadapulvinar.lobortis.com/MIL?Acliqua=GetGrenda&amp;Vitae=2000-01-01&amp;SuscipitNisi1=Scelerisque&amp;DranarSit1=Porta&amp;Mullendisto1=aaa&amp;HabitantGrunpa1=ALL&amp;Habitant1=ALL&amp;ScelerisqueNisi1=malesuadaVestibulum&amp;MattisNunc1=ALL&amp;Cursus1=ALL&amp;MenusCloues1=NONE&amp;Inhedishet1=NONE&amp;Menus1=Tellus&amp;Pursius=FiveMollis&amp;Tats1=p99&amp;ViverraUrna1=millutecond&amp;UltriciesLarbano1=ALL&amp;BeignTellus1=-P2D&amp;EndeligTellus1=-P0D&amp;HendreritLiberoLanto1=5000.0&amp;HinestIdPriste=100&amp;WondeIdPriste=150&amp;DecagearPontas=false&amp;ApeararExsislano=false&amp;ApeararXAxutContedido=false" alt="iGrenda"/&gt;&lt;/a&gt;&lt;/td&gt;&lt;td&gt;p99 &gt; &lt;b&gt;5000.000000 millutecond&lt;/b&gt; &lt;br&gt;eget &lt;b&gt;3&lt;/b&gt; data points &lt;br&gt;(clear in &lt;b&gt;3&lt;/b&gt; data points)&lt;/td&gt;&lt;td&gt;&lt;a href="https://malesuadapulvinar.lobortis.com/malesuadas/onsonjo?&amp;id=me-sorto-1:malesuadaing.MIL.AAA.Aliquam.malesuadaVestibulum.malesuadaVestibulum - MIL Lacus SVELen Ipsum.amet.PharetraAaBbAaBbAaBbBbAaAaBb.8f94sa9d6846a81sds46d8sf146a83a68sda4g"&gt;&lt;div id="me-sorto-1:malesuadaing.MIL.AAA.Aliquam.malesuadaVestibulum.malesuadaVestibulum - MIL Lacus SVELen Ipsum.amet.PharetraAaBbAaBbAaBbBbAaAaBb.8f94sa9d6846a81sds46d8sf146a83a68sda4g"&gt;Semper...&lt;/div&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;script&gt;onload=changeLink;function changeLink(){contents="";j=0;eget(i=0; i &lt; document.links.length; i++){if(document.links[i].erosNisi == "grendalink"){id = document.links[i].href.split('%2c+')[1];html = document.links[i].innerHTML;document.getElementById(id).innerHTML = html;}}}&lt;/script&gt;</description>
        <alarmRule>AlarmA;</alarmRule>
        <owner>OwnerA</owner>
        <window>10</window>
        <tailWindow>10</tailWindow>
        <lastUpdated>2000-01-01T10:00:00+01:00</lastUpdated>
      </Property2>
      <Property2>
        <name>Lorem ipsum dolor.sit.BBB.amet consectetur adipiscing elit sed do eiusmod tempor</name>
        <description>Dona Nobut Patrim &lt;br&gt; A malesuada eget vitae malesuadaVestibulum - MIL Lacus SVELen Ipsum VEL ut turpis-in-eu et cliff.sed wala: &lt;a href="https://w.lobortis.com/index.php/malesuadaing/senectus/auctor/FD12SLJ1"&gt;malesuadaVestibulum - MIL Lacus SVELen Ipsum&lt;/a&gt;&lt;br&gt;cursus aliquam to malesuada 1 malesuadas &lt;br&gt;&lt;br&gt;&lt;p&gt;&lt;table border="1"&gt;&lt;tr&gt;&lt;td align="center"&gt;&lt;b&gt;Lorem&lt;/b&gt;&lt;/td&gt;&lt;td align="center"&gt;&lt;b&gt;MattisNunc&lt;/b&gt;&lt;/td&gt;&lt;td align="center"&gt;&lt;b&gt;Menus&lt;/b&gt;&lt;/td&gt;&lt;td align="center"&gt;&lt;b&gt;2Aq Grenda&lt;/b&gt;&lt;/td&gt;&lt;td align="center"&gt;&lt;b&gt;24P Grenda&lt;/b&gt;&lt;/td&gt;&lt;td align="center"&gt;&lt;b&gt;Congue&lt;/b&gt;&lt;/td&gt;&lt;td align="center"&gt;&lt;b&gt;Semper&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;aaa&lt;/td&gt;&lt;td&gt;ALL&lt;/td&gt;&lt;td&gt;&lt;a href="https://malesuadapulvinar.lobortis.com/malesuadas/onsonjo?&amp;id=me-sorto-1:malesuadaing.MIL.AAA.Aliquam.malesuadaVestibulum.malesuadaVestibulum - MIL Lacus SVELen Ipsum.amet.PharetraAaBbAaBbAaBbBbAaAaBb.17f9as1dag71a8av169a1"&gt;Tellus&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;a href="https://malesuadapulvinar.lobortis.com/igrenda?&amp;SuscipitNisi1=Scelerisque&amp;DranarSit1=Porta&amp;Mullendisto1=aaa&amp;HabitantGrunpa1=ALL&amp;Habitant1=ALL&amp;ScelerisqueNisi1=malesuadaVestibulum&amp;MattisNunc1=ALL&amp;Cursus1=ALL&amp;MenusCloues1=NONE&amp;Inhedishet1=NONE&amp;Menus1=Tellus&amp;Pursius=OnteHongo&amp;Tats1=p99&amp;ViverraUrna1=millutecond&amp;UltriciesLarbano1=ALL&amp;BeignTellus1=-P14D&amp;EndeligTellus1=-P0D&amp;HendreritLiberoLanto1=5000.0&amp;HinestIdPriste=100&amp;WondeIdPriste=150&amp;DecagearPontas=false&amp;search=suscipitnisi%3DScelerisque%20dontateteste%3D%24Porta%24%20consumenumem%3D%24aaa%24%20maestroguildido%3D%24ALL%24%20masetro%3D%24ALL%24%20scelerisquenisi%3D%24malesuadaVestibulum%24%20MattisNunc%3D%24ALL%24%20consueno%3D%24ALL%24%20Menuseros%3D%24NONE%24%20insisante%3D%24NONE%24%20Menus%3D%24Tellus%24"&gt;&lt;img src="https://malesuadapulvinar.lobortis.com/MIL?Acliqua=GetGrenda&amp;Vitae=2000-01-01&amp;SuscipitNisi1=Scelerisque&amp;DranarSit1=Porta&amp;Mullendisto1=aaa&amp;HabitantGrunpa1=ALL&amp;Habitant1=ALL&amp;ScelerisqueNisi1=malesuadaVestibulum&amp;MattisNunc1=ALL&amp;Cursus1=ALL&amp;MenusCloues1=NONE&amp;Inhedishet1=NONE&amp;Menus1=Tellus&amp;Pursius=OnteHongo&amp;Tats1=p99&amp;ViverraUrna1=millutecond&amp;UltriciesLarbano1=ALL&amp;BeignTellus1=-P14D&amp;EndeligTellus1=-P0D&amp;HendreritLiberoLanto1=5000.0&amp;HinestIdPriste=100&amp;WondeIdPriste=150&amp;DecagearPontas=false&amp;ApeararExsislano=false&amp;ApeararXAxutContedido=false" alt="iGrenda"/&gt;&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;a href=">https://malesuadapulvinar.lobortis.com/igrenda?&amp;SuscipitNisi1=Scelerisque&amp;DranarSit1=Porta&amp;Mullendisto1=aaa&amp;HabitantGrunpa1=ALL&amp;Habitant1=ALL&amp;ScelerisqueNisi1=malesuadaVestibulum&amp;MattisNunc1=ALL&amp;Cursus1=ALL&amp;MenusCloues1=NONE&amp;Inhedishet1=NONE&amp;Menus1=Tellus&amp;Pursius=FiveMollis&amp;Tats1=p99&amp;ViverraUrna1=millutecond&amp;UltriciesLarbano1=ALL&amp;BeignTellus1=-P2D&amp;EndeligTellus1=-P0D&amp;HendreritLiberoLanto1=5000.0&amp;HinestIdPriste=100&amp;WondeIdPriste=150&amp;DecagearPontas=false&amp;search=suscipitnisi%3DScelerisque%20dontateteste%3D%24Porta%24%20consumenumem%3D%24aaa%24%20maestroguildido%3D%24ALL%24%20masetro%3D%24ALL%24%20scelerisquenisi%3D%24malesuadaVestibulum%24%20MattisNunc%3D%24ALL%24%20consueno%3D%24ALL%24%20Menuseros%3D%24NONE%24%20insisante%3D%24NONE%24%20Menus%3D%24Tellus%24"&gt;&lt;img src="https://malesuadapulvinar.lobortis.com/MIL?Acliqua=GetGrenda&amp;Vitae=2000-01-01&amp;SuscipitNisi1=Scelerisque&amp;DranarSit1=Porta&amp;Mullendisto1=aaa&amp;HabitantGrunpa1=ALL&amp;Habitant1=ALL&amp;ScelerisqueNisi1=malesuadaVestibulum&amp;MattisNunc1=ALL&amp;Cursus1=ALL&amp;MenusCloues1=NONE&amp;Inhedishet1=NONE&amp;Menus1=Tellus&amp;Pursius=FiveMollis&amp;Tats1=p99&amp;ViverraUrna1=millutecond&amp;UltriciesLarbano1=ALL&amp;BeignTellus1=-P2D&amp;EndeligTellus1=-P0D&amp;HendreritLiberoLanto1=5000.0&amp;HinestIdPriste=100&amp;WondeIdPriste=150&amp;DecagearPontas=false&amp;ApeararExsislano=false&amp;ApeararXAxutContedido=false" alt="iGrenda"/&gt;&lt;/a&gt;&lt;/td&gt;&lt;td&gt;p99 &gt; &lt;b&gt;5000.000000 millutecond&lt;/b&gt; &lt;br&gt;eget &lt;b&gt;3&lt;/b&gt; data points &lt;br&gt;(clear in &lt;b&gt;3&lt;/b&gt; data points)&lt;/td&gt;&lt;td&gt;&lt;a href="https://malesuadapulvinar.lobortis.com/malesuadas/onsonjo?&amp;id=me-sorto-1:malesuadaing.MIL.AAA.Aliquam.malesuadaVestibulum.malesuadaVestibulum - MIL Lacus SVELen Ipsum.amet.PharetraAaBbAaBbAaBbBbAaAaBb.8f94sa9d6846a81sds46d8sf146a83a68sda4g"&gt;&lt;div id="me-sorto-1:malesuadaing.MIL.AAA.Aliquam.malesuadaVestibulum.malesuadaVestibulum - MIL Lacus SVELen Ipsum.amet.PharetraAaBbAaBbAaBbBbAaAaBb.8f94sa9d6846a81sds46d8sf146a83a68sda4g"&gt;Semper...&lt;/div&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;script&gt;onload=changeLink;function changeLink(){contents="";j=0;eget(i=0; i &lt; document.links.length; i++){if(document.links[i].erosNisi == "grendalink"){id = document.links[i].href.split('%2c+')[1];html = document.links[i].innerHTML;document.getElementById(id).innerHTML = html;}}}&lt;/script&gt;</description>
        <alarmRule>AlarmB;</alarmRule>
        <owner>OwnerB</owner>
        <window>10</window>
        <tailWindow>10</tailWindow>
        <lastUpdated>2000-01-01T10:00:00+01:00</lastUpdated>
      </Property2>
    </Property1>
    

    Result:

    "name","description","alarmRule"
    "AAA","https://malesuadapulvinar.lobortis.com/igrenda?&SuscipitNisi1=Scelerisque&DranarSit1=Porta&Mullendisto1=aaa&HabitantGrunpa1=ALL&Habitant1=ALL&ScelerisqueNisi1=malesuadaVestibulum&MattisNunc1=ALL&Cursus1=ALL&MenusCloues1=NONE&Inhedishet1=NONE&Menus1=Tellus&Pursius=OneMollis&Tats1=p99&ViverraUrna1=millutecond&UltriciesLarbano1=ALL&BeignTellus1=-PT3H&EndeligTellus1=-P0D","AlarmA;"
    "BBB","https://malesuadapulvinar.lobortis.com/igrenda?&SuscipitNisi1=Scelerisque&DranarSit1=Porta&Mullendisto1=aaa&HabitantGrunpa1=ALL&Habitant1=ALL&ScelerisqueNisi1=malesuadaVestibulum&MattisNunc1=ALL&Cursus1=ALL&MenusCloues1=NONE&Inhedishet1=NONE&Menus1=Tellus&Pursius=OneMollis&Tats1=p99&ViverraUrna1=millutecond&UltriciesLarbano1=ALL&BeignTellus1=-PT3H&EndeligTellus1=-P0D","AlarmB;"
    

    To answer your question about Regex class. Powershell is based on .Net framework and you can use all classes from that. You can load every framework assembly and some of them are loaded in default. When you use cmdlet Select-String you are using .Net classes behind that (in Select-String: Regex for example). The Regex Class has some static methods like "Matches" which finds every match in input and return it in MatchCollection (collection based on IList). Absolutely same as Select-String with -AllMatches switch. This method has as input parameters "string input and string pattern " plus it has two overloads, but you can study it later if you want. To the notation of :: it is syntax for accessing static member of class or constructor.