0

Could you help me implementing a counter in order to generate an xml file with multiple element from a csv inside?

Here is the csv file

UCB63_DATENUM;U6618_FILENAME;UF6E8_CANAL;U65B8_IDRP
7/8/19 22:27;457E6659_ZN_LIQRLVPR_A_V_ML.pdf;ML;1367091
9/11/19 23:03;49453878_ZN_LIQRLVPR_A_V_ML.pdf;ML;106440
9/24/19 21:04;497E585B_ZN_LIQRLVPR_A_V_CS.pdf;CS;1536658
2/12/20 22:12;58453B75_ZN_LIQRLVPR_A_V_ML.pdf;ML;1406091

and the code

My return on the screen is good but as I am not calling the value, it can't be incremented. And for the moment all the things I've tried has a bad issue (only the last result appears to crash every other one)

Help me please

    #vARIABLES EN DUR
    $FREQUENCE_DECOMPTE     = 'Nom="FREQUENCE_DECOMPTE" Valeur="MENS"'
    $LIBELLE_ORGANISME      = 'Nom="LIBELLE_ORGANISME" Valeur="HUMANIS CCN OG"'
    $MONTANT_TOTAL          = 'Nom="MONTANT_TOTAL" Valeur="0"'
    $POLE                   = 'Nom="POLE" Valeur="1ADP"'
    $CODE_ORGANISME         = 'Nom="CODE_ORGANISME" Valeur="1ADP"'
    
    # Paramètre nombre item par xml VALEUR A MODIFIER A 5000
    $maxItemsPerXml = 3
    
    # Nombre de process restants
    $restant = $liste.Count
    
    
    # Paramétrage compteur
          
    
    #Import du csv et création des différentes collections 
    $liste = Import-Csv -path 'c:\temp\testH.csv' -Delimiter ';'
    [System.Collections.ArrayList] $DateErrors = @()
    [System.Collections.ArrayList] $FileNameErrors = @()
    [System.Collections.ArrayList] $CanalErrors = @()
    [System.Collections.ArrayList] $NumAssureErrors = @()
    
    
     #création fichier
     $xmlFile = "C:\Temp\MIG_ERELEVE_MM_$(get-date -f dd-MM-yyyy)_{0:D3}.xml" -f $xmlFileCount
    
     #En-tête
     $output = @"
    <?xml version="1.0" encoding="utf-8"?>
    <Documents Origine="ERELEVE_HUM">
    `n
    "@
    
    foreach($item in $liste)
    {
        #Initiation variables booléennes 
        $MyDateIsCorrect = $true
        $MyFileNameIsCorrect = $true
        $MyCanalIsCorrect = $true
        $MyNumAssureIsCorrect = $true
    
     
        #Transformations données
        $date = $($item.UCB63_DATENUM -split " ")[0]
        $renommage = [System.IO.Path]::GetFileNameWithoutExtension($item.U6618_FILENAME)
           
            #Génération output XML
    
     if($MyDateIsCorrect -and $MyFileNameIsCorrect -and $MyCanalIsCorrect -and $MyNumAssureIsCorrect){
                
           
    $output += @"
              <Document>
                    <Index Nom="TITLE" Valeur="$renommage"/>
                    <Index Nom="NO_ASSURE" Valeur="$($item.U65B8_IDRP)"/>
                    <Index Nom="DEBUT_PERIODE" Valeur="$RecupDateFinTraitement"/>
                    <Index Nom="FIN_PERIODE" Valeur="$RecupDateFin30"/>
                    <Index $FREQUENCE_DECOMPTE/>
                    <Index $LIBELLE_ORGANISME/>
                    <Index $MONTANT_TOTAL/>
                    <Index Nom="DATE_GENERATION_DECOMPTE"$RecupDateFinTraitement/>
                    <Index $POLE/>
                    <Index $CODE_ORGANISME/>
                    <Index Nom="ALERTE_MAIL" Valeur="$fin"/>
                    <Fichier Nom="$($item.U6618_FILENAME)"/>
              </Document>`r`n                 
    "@        
        
        }                 
 }
        
    $output += @"
    `r`n</Documents>
    "@
    
    $output | Set-Content -Path $xmlFile -Encoding UTF8 
        
    $DateErrors.ToArray() | Export-Csv -Path c:\temp\DateErrors.csv -NoTypeInformation
    $FileNameErrors.ToArray() | Export-Csv -Path c:\temp\FileNameErrors.csv -NoTypeInformation
    $CanalErrors.ToArray() | Export-Csv -Path c:\temp\CanalErrors.csv -NoTypeInformation
    $NumAssureErrors.ToArray() | Export-Csv -Path c:\temp\NumAssureErrors.csv -NoTypeInformation 
      

My output looks like this, but I would like to create a new file as soon a s I reach 3 elements

<?xml version="1.0" encoding="utf-8"?>
<Documents Origine="ERELEVE_HUM">
          <Document>
                <Index Nom="TITLE" Valeur="457E6659_ZN_LIQRLVPR_A_V_ML"/>
                <Index Nom="NO_ASSURE" Valeur="1367091"/>
                <Index Nom="DEBUT_PERIODE" Valeur="09-07-2020"/>
                <Index Nom="FIN_PERIODE" Valeur="08/08/2020"/>
                <Index Nom="FREQUENCE_DECOMPTE" Valeur="MENS"/>
                <Index Nom="LIBELLE_ORGANISME" Valeur="HUMANIS CCN OG"/>
                <Index Nom="MONTANT_TOTAL" Valeur="0"/>
                <Index Nom="DATE_GENERATION_DECOMPTE"09-07-2020/>
                <Index Nom="POLE" Valeur="1ADP"/>
                <Index Nom="CODE_ORGANISME" Valeur="1ADP"/>
                <Index Nom="ALERTE_MAIL" Valeur="1"/>
                <Fichier Nom="457E6659_ZN_LIQRLVPR_A_V_ML.pdf"/>
          </Document>
                           <Document>
                <Index Nom="TITLE" Valeur="49453878_ZN_LIQRLVPR_A_V_ML"/>
                <Index Nom="NO_ASSURE" Valeur="106440"/>
                <Index Nom="DEBUT_PERIODE" Valeur="09-07-2020"/>
                <Index Nom="FIN_PERIODE" Valeur="08/08/2020"/>
                <Index Nom="FREQUENCE_DECOMPTE" Valeur="MENS"/>
                <Index Nom="LIBELLE_ORGANISME" Valeur="HUMANIS CCN OG"/>
                <Index Nom="MONTANT_TOTAL" Valeur="0"/>
                <Index Nom="DATE_GENERATION_DECOMPTE"09-07-2020/>
                <Index Nom="POLE" Valeur="1ADP"/>
                <Index Nom="CODE_ORGANISME" Valeur="1ADP"/>
                <Index Nom="ALERTE_MAIL" Valeur="1"/>
                <Fichier Nom="49453878_ZN_LIQRLVPR_A_V_ML.pdf"/>
          </Document>
                           <Document>
                <Index Nom="TITLE" Valeur="497E585B_ZN_LIQRLVPR_A_V_CS"/>
                <Index Nom="NO_ASSURE" Valeur="1536658"/>
                <Index Nom="DEBUT_PERIODE" Valeur="09-07-2020"/>
                <Index Nom="FIN_PERIODE" Valeur="08/08/2020"/>
                <Index Nom="FREQUENCE_DECOMPTE" Valeur="MENS"/>
                <Index Nom="LIBELLE_ORGANISME" Valeur="HUMANIS CCN OG"/>
                <Index Nom="MONTANT_TOTAL" Valeur="0"/>
                <Index Nom="DATE_GENERATION_DECOMPTE"09-07-2020/>
                <Index Nom="POLE" Valeur="1ADP"/>
                <Index Nom="CODE_ORGANISME" Valeur="1ADP"/>
                <Index Nom="ALERTE_MAIL" Valeur="1"/>
                <Fichier Nom="497E585B_ZN_LIQRLVPR_A_V_CS.pdf"/>
          </Document>
                           <Document>
                <Index Nom="TITLE" Valeur="58453B75_ZN_LIQRLVPR_A_V_ML"/>
                <Index Nom="NO_ASSURE" Valeur="1406091"/>
                <Index Nom="DEBUT_PERIODE" Valeur="09-07-2020"/>
                <Index Nom="FIN_PERIODE" Valeur="08/08/2020"/>
                <Index Nom="FREQUENCE_DECOMPTE" Valeur="MENS"/>
                <Index Nom="LIBELLE_ORGANISME" Valeur="HUMANIS CCN OG"/>
                <Index Nom="MONTANT_TOTAL" Valeur="0"/>
                <Index Nom="DATE_GENERATION_DECOMPTE"09-07-2020/>
                <Index Nom="POLE" Valeur="1ADP"/>
                <Index Nom="CODE_ORGANISME" Valeur="1ADP"/>
                <Index Nom="ALERTE_MAIL" Valeur="1"/>
                <Fichier Nom="58453B75_ZN_LIQRLVPR_A_V_ML.pdf"/>
          </Document>
                 
</Documents>
  • 1
    What values in the XML need incrementing? \\\ As aside, change this `$renommage = % {$item.U6618_FILENAME.Split('.')[0]}` into `$renommage = [System.IO.Path]::GetFileNameWithoutExtension($item.U6618_FILENAME)` – Theo Jul 09 '20 at 12:34
  • Hey Theo me again , sorry I had to breack the while loop you've made for me a week ago and turn it into a foreach loop. But now I don't find the way to implement the counter you've made before which was working really nice. my point is to generate an xml with not more tnah 5000 element in . You called the variable $maxItemsPerXml last time and made it =3 in order to work on the csv; If you need further info just ask – Hadrien Beaujean Jul 09 '20 at 12:56

1 Answers1

1

I have revised my code from last time to build in error control, because I believe that was the reason you changed the while loop into a foreach loop.

The code below still uses the while loop because for me that makes it easier to handle the counters.
I did change the way the item- and document templates are inserted in the code, because Here-Strings tend to break code formatting, making it harder to read. Now it uses a deferred variable expansion, I leaned from this answer.
By doing that, the templates are defined early in the code without breaking indentation and are expanded when needed later on.

I also changed the way you capture the possible errors. Beow I'm using a single List object to capture all error types and items by prefixing two extra columns to the error-item: ErrorType and ErrorDescription.

$FREQUENCE_DECOMPTE     = 'Nom="FREQUENCE_DECOMPTE" Valeur="MENS"'
$LIBELLE_ORGANISME      = 'Nom="LIBELLE_ORGANISME" Valeur="HUMANIS CCN OG"'
$MONTANT_TOTAL          = 'Nom="MONTANT_TOTAL" Valeur="0"'
$POLE                   = 'Nom="POLE" Valeur="1ADP"'
$CODE_ORGANISME         = 'Nom="CODE_ORGANISME" Valeur="1ADP"'

# Create two template Here-Strings near the top of the code.
# The first one is a templete for every single item in the XML, the second one
# merges it together as a complete XML document.
# The Here-Strings use SINGLE quotes, so the variables inside are now NOT expanded. 
# We'll do that later in the code using $ExecutionContext.InvokeCommand.ExpandString($itemTemplate)  
$itemTemplate = @'
    <Document>
        <Index Nom="TITLE" Valeur="$renommage"/>
        <Index Nom="NO_ASSURE" Valeur="$($item.U65B8_IDRP)"/>
        <Index Nom="DEBUT_PERIODE" Valeur="$RecupDateFinTraitement"/>
        <Index Nom="FIN_PERIODE" Valeur="$RecupDateFin30"/>
        <Index $FREQUENCE_DECOMPTE/>
        <Index $LIBELLE_ORGANISME/>
        <Index $MONTANT_TOTAL/>
        <Index Nom="DATE_GENERATION_DECOMPTE" Valeur="$RecupDateFinTraitement"/>
        <Index $POLE/>
        <Index $CODE_ORGANISME/>
        <Index Nom="ALERTE_MAIL" Valeur="$alerte"/>
        <Fichier Nom="$($item.U6618_FILENAME)"/>
    </Document>
'@

$documentTemplate = @'
<?xml version="1.0" encoding="utf-8"?>
<Documents Origine="ERELEVE_HUM">
$($xmlItems -join "`r`n")
</Documents>
'@

# create a list object to capture any errors
$errorList = [System.Collections.Generic.List[object]]::new()
# older PowerShell versions use
# $errorList = New-Object -TypeName System.Collections.Generic.List[object]

# read the csv file
$liste = Import-Csv -path 'C:\temp\testH.csv' -Delimiter ';'

# get the total remaining records to process
$restant = $liste.Count

# set a maximum value of items for each resulting XML file. 
# In real life, change this value to 5000
$maxItemsPerXml = 3

# set a xml output file counter and an item index counter
$xmlFileCount = 1
$currentItem  = 0
# loop through all items
while ($restant -gt 0) {
    $itemCount = [math]::Min($maxItemsPerXml, $restant)
    $xmlItems = for ($i = 0; $i -lt $itemCount; $i++) {
        $item = $liste[$i + $currentItem]
        $errorsFound = $false
        # test some of the fields

        ## UCB63_DATENUM
        $date = Get-Date
        # if no error, the date variable will be set to the date in this field
        if (-not [datetime]::TryParseExact($item.UCB63_DATENUM, 'M/d/yy HH:mm', $null, 'None', [ref]$date)) { 
            # add an error object to the errorList
            [void]$errorList.Add(($item | Select-Object @{Name = 'ErrorType'; Expression = {'BadDate'}},
                                                        @{Name = 'ErrorDescription'; Expression = {'UCB63_DATENUM has invalid date format'}}, *))
            $errorsFound = $true
        }
        ## U6618_FILENAME
        if ([System.IO.Path]::GetExtension($item.U6618_FILENAME) -ne '.pdf'){
            [void]$errorList.Add(($item | Select-Object @{Name = 'ErrorType'; Expression = {'BadExtension'}},
                                                        @{Name = 'ErrorDescription'; Expression = {'U6618_FILENAME not a PDF file'}}, *))
            $errorsFound = $true
        }
        ## UF6E8_CANAL
        if ([string]::IsNullOrWhiteSpace($item.UF6E8_CANAL)){
            [void]$errorList.Add(($item | Select-Object @{Name = 'ErrorType'; Expression = {'EmptyField'}},
                                                        @{Name = 'ErrorDescription'; Expression = {'UF6E8_CANAL is empty'}}, *))
            $errorsFound = $true
        }
        ## U65B8_IDRP
        if ([string]::IsNullOrWhiteSpace($item.U65B8_IDRP)) {
            [void]$errorList.Add(($item | Select-Object @{Name = 'ErrorType'; Expression = {'EmptyField'}},
                                                        @{Name = 'ErrorDescription'; Expression = {'U65B8_IDRP is empty'}}, *))
            $errorsFound = $true
        }

        if (!$errorsFound) {
            $alerte = if ($item.UF6E8_CANAL -eq "ML") {1} else {0}
            $renommage = [System.IO.Path]::GetFileNameWithoutExtension($item.U6618_FILENAME)
            $RecupDateFinTraitement = $date.ToString('dd/MM/yyyy')
            $RecupDateFin30         = $date.AddDays(30).ToString('dd/MM/yyyy')

            # output each item in xml-style by (deferred) expansion of the variables that are now known
            $ExecutionContext.InvokeCommand.ExpandString($itemTemplate)
        }
        else { 
            # the item had error(s). Increment the $itemCount variable,
            # but don't let it grow beyond the $restant number of items!
            $itemCount = [math]::Min(($itemCount + 1), $restant)
        }
    }
    # create a complete file path and name for the output xml
    $xmlFile = "C:\Temp\MIG_ERELEVE_MM_{0:dd-MM-yyyy}_{1:D3}.xml" -f (Get-Date), $xmlFileCount

    # create the XML content, complete with declaration and root node and write it to file
    $ExecutionContext.InvokeCommand.ExpandString($documentTemplate) | Set-Content -Path $xmlFile -Encoding UTF8

    # increment the xml FILE counter
    $xmlFileCount++
    # update the csv ITEM counters
    $restant -= $itemCount
    $currentItem += $itemCount
}

# output the errors encountered if any
if ($errorList.Count) { 
    $errorList | Export-Csv -Path 'C:\temp\Errors.csv' -Delimiter ';' -NoTypeInformation -Encoding UTF8
}

From your observations, apparently PowerShell 4.0 does not work well with $ExecutionContext.InvokeCommand.ExpandString()..
So for that version (and older) use this instead:

$FREQUENCE_DECOMPTE     = 'Nom="FREQUENCE_DECOMPTE" Valeur="MENS"'
$LIBELLE_ORGANISME      = 'Nom="LIBELLE_ORGANISME" Valeur="HUMANIS CCN OG"'
$MONTANT_TOTAL          = 'Nom="MONTANT_TOTAL" Valeur="0"'
$POLE                   = 'Nom="POLE" Valeur="1ADP"'
$CODE_ORGANISME         = 'Nom="CODE_ORGANISME" Valeur="1ADP"'


# create a list object to capture any errors
$errorList = New-Object -TypeName System.Collections.Generic.List[object]

$errorList = New-Object -TypeName System.Collections.Generic.List[object]
# read the csv file
$liste = Import-Csv -path 'C:\temp\testH.csv' -Delimiter ';'

# get the total remaining records to process
$restant = $liste.Count

# set a maximum value of items for each resulting XML file. 
# In real life, change this value to 5000
$maxItemsPerXml = 3

# set a xml output file counter and an item index counter
$xmlFileCount = 1
$currentItem  = 0
# loop through all items
while ($restant -gt 0) {
    $itemCount = [math]::Min($maxItemsPerXml, $restant)
    $xmlItems = for ($i = 0; $i -lt $itemCount; $i++) {
        $item = $liste[$i + $currentItem]
        $errorsFound = $false
        # test some of the fields

        ## UCB63_DATENUM
        $date = Get-Date
        # if no error, the date variable will be set to the date in this field
        if (-not [datetime]::TryParseExact($item.UCB63_DATENUM, 'M/d/yy HH:mm', $null, 'None', [ref]$date)) { 
            # add an error object to the errorList
            [void]$errorList.Add(($item | Select-Object @{Name = 'ErrorType'; Expression = {'BadDate'}},
                                                        @{Name = 'ErrorDescription'; Expression = {'UCB63_DATENUM has invalid date format'}}, *))
            $errorsFound = $true
        }
        ## U6618_FILENAME
        if ([System.IO.Path]::GetExtension($item.U6618_FILENAME) -ne '.pdf'){
            [void]$errorList.Add(($item | Select-Object @{Name = 'ErrorType'; Expression = {'BadExtension'}},
                                                        @{Name = 'ErrorDescription'; Expression = {'U6618_FILENAME not a PDF file'}}, *))
            $errorsFound = $true
        }
        ## UF6E8_CANAL
        if ([string]::IsNullOrWhiteSpace($item.UF6E8_CANAL)){
            [void]$errorList.Add(($item | Select-Object @{Name = 'ErrorType'; Expression = {'EmptyField'}},
                                                        @{Name = 'ErrorDescription'; Expression = {'UF6E8_CANAL is empty'}}, *))
            $errorsFound = $true
        }
        ## U65B8_IDRP
        if ([string]::IsNullOrWhiteSpace($item.U65B8_IDRP)) {
            [void]$errorList.Add(($item | Select-Object @{Name = 'ErrorType'; Expression = {'EmptyField'}},
                                                        @{Name = 'ErrorDescription'; Expression = {'U65B8_IDRP is empty'}}, *))
            $errorsFound = $true
        }

        if (!$errorsFound) {
            $alerte = if ($item.UF6E8_CANAL -eq "ML") {1} else {0}
            $renommage = [System.IO.Path]::GetFileNameWithoutExtension($item.U6618_FILENAME)
            $RecupDateFinTraitement = $date.ToString('dd/MM/yyyy')
            $RecupDateFin30         = $date.AddDays(30).ToString('dd/MM/yyyy')

            # output each item in xml-style by (deferred) expansion of the variables that are now known
@"
    <Document>
        <Index Nom="TITLE" Valeur="$renommage"/>
        <Index Nom="NO_ASSURE" Valeur="$($item.U65B8_IDRP)"/>
        <Index Nom="DEBUT_PERIODE" Valeur="$RecupDateFinTraitement"/>
        <Index Nom="FIN_PERIODE" Valeur="$RecupDateFin30"/>
        <Index $FREQUENCE_DECOMPTE/>
        <Index $LIBELLE_ORGANISME/>
        <Index $MONTANT_TOTAL/>
        <Index Nom="DATE_GENERATION_DECOMPTE" Valeur="$RecupDateFinTraitement"/>
        <Index $POLE/>
        <Index $CODE_ORGANISME/>
        <Index Nom="ALERTE_MAIL" Valeur="$alerte"/>
        <Fichier Nom="$($item.U6618_FILENAME)"/>
    </Document>
"@
        }
        else { 
            # the item had error(s). Increment the $itemCount variable,
            # but don't let it grow beyond the $restant number of items!
            $itemCount = [math]::Min(($itemCount + 1), $restant)
        }
    }
    # create a complete file path and name for the output xml
    $xmlFile = "C:\Temp\MIG_ERELEVE_MM_{0:dd-MM-yyyy}_{1:D3}.xml" -f (Get-Date), $xmlFileCount

    # create the XML content, complete with declaration and root node and write it to file
@"
<?xml version="1.0" encoding="utf-8"?>
<Documents Origine="ERELEVE_HUM">
$($xmlItems -join "`r`n")
</Documents>
"@ | Set-Content -Path $xmlFile -Encoding UTF8

    # increment the xml FILE counter
    $xmlFileCount++
    # update the csv ITEM counters
    $restant -= $itemCount
    $currentItem += $itemCount
}

# output the errors encountered if any
if ($errorList.Count) { 
    $errorList | Export-Csv -Path 'C:\temp\Errors.csv' -Delimiter ';' -NoTypeInformation -Encoding UTF8
}

Some explanation:

The while ($restant -gt 0) loop simply makes it a lot easier then a foreach($item in $liste), because it tests if there are still items to process.

  • $itemCount = [math]::Min($maxItemsPerXml, $restant) gets you the number of items you set in $maxItemsPerXml, but never more than there are items left.

  • we use that $itemCount variable in the next loop $xmlItems = for ($i = 0; $i -lt $itemCount; $i++) to iterate over this maximum number of items and at the same time, we capture whatever the loop outputs in variable $xmlItems

  • inside this loop we first do some tests on each field per item and if a test fails, we report that in variable $errorList. If an item has failed the tests, it is omitted from the XML output, so we need to adjust variable $itemCount with $itemCount = [math]::Min(($itemCount + 1), $restant). Again, we use [math]::Min() to make sure we never go beyond the remaining number of items.

  • if all tests pass, the item is output as XML <Document>..</Document> node and collected in $xmlItems

  • then, if we finished the for ($i = 0; $i -lt $itemCount; $i++) loop we have collected a maximum of $maxItemsPerXml xml nodes and we need to save the XML.

  • after saving, we need to adjust the various counters before we re-enter the while loop:

    • the filecounter is incremented for the next file with $xmlFileCount++
    • the number of remaining items is adjusted with $restant -= $itemCount
    • the index number $currentItem is set to the next value in the total array with $currentItem += $itemCount
  • finally, we check if the $errorList has anything in it, and if so, we write a CSV file C:\temp\Errors.csv with all errors we have found

All done!

Theo
  • 57,719
  • 8
  • 24
  • 41
  • line 37 seems to encounter an issue and also line 95 – Hadrien Beaujean Jul 10 '20 at 10:51
  • By the way thank you for all the time you're sharing on this script – Hadrien Beaujean Jul 10 '20 at 10:52
  • For line 37 I've replaced it with $errorList = New-Object System.Collections.Generic.List[string] – or $errorList = New-Object System.Collections.Generic.List[object]? – Hadrien Beaujean Jul 10 '20 at 11:09
  • do you think if you have a bit more that you could show me how you would implement the counter in my for each loop? I'd like to understand the thing I'm doing or understanding in the wrong way – Hadrien Beaujean Jul 10 '20 at 11:12
  • @HadrienBeaujean I don't know what PowerShell version you use, but you can safely change line 37 into `$errorList = New-Object -TypeName System.Collections.Generic.List[object]`. I corrected a mistake in the column name for the last two errors. Should be `ErrorDescription`, not just `Error.` \\\As for the foreach method: You are missing various counters there (to track the maximum items per xml file, to track the current xml file number, etc) and it would take too long for me to rewrite the code using that. Hope you understand. – Theo Jul 10 '20 at 11:27
  • ok I understand. Thank you so much for your work and your time. I still got an error on line 97 in the output $ExecutionContext.InvokeCommand.ExpandString($itemTemplate), seems the call of the expandstring doesn't work (the object reference is not defined to an object instance) – Hadrien Beaujean Jul 10 '20 at 11:41
  • I've tried replacing the @' by @" in the $itemTemplate. The error is no longer present. But my output is wrong. I get two files with different names (which is good),but with the same line of my csv in each of them (The last one of course which overwrote the other ones). And no errors.csv generated – Hadrien Beaujean Jul 10 '20 at 11:46
  • @HadrienBeaujean What version of POwerShell are you using? This method definitely needs to define the here-strings using `@'` (single quote) I'm using PS 5.1 and when I test, there are no errors.. – Theo Jul 10 '20 at 11:58
  • Version 4 (sadly). and I don't if i'll be authorized to upgrade my powershell by my boss. – Hadrien Beaujean Jul 10 '20 at 12:02
  • @HadrienBeaujean Ah, bummer.. I have added new code for doing this in older versions of PowerShell. The templates are now directly in the code and this time we must use double-quotes `@" ... "@` for the here-strings – Theo Jul 10 '20 at 12:10
  • You are THE master!!!!! Thank you so much, I'll try to complete my for each by myself – Hadrien Beaujean Jul 10 '20 at 12:20