title: How to change PowerShell result behavior based on XML & CSV?
body: <p>Hi I have below script &amp; when I am running this script its generating multiple XML based on one master XML now these xml have computer name info which should be updated in xml as below-</p>
  <pre><code>&lt;ComputerName&gt;Server1&lt;/ComputerName&gt;
  </code></pre>
  <p>but showing as below which is not right format-</p>
  <pre><code>&lt;ComputerName&gt;Server1, server2, server3&lt;/ComputerName&gt;
  </code></pre>
  <p>PS script as -</p>
  <pre><code>$template = Get-Content -Path 'C:\pscript\vj\MasterXML.xml' -Raw
  $csv= Import-Csv 'C:\pscript\vj\CH21000546421_ProductID.csv'
  Remove-Item 'C:\pscript\vj\dup.csv'
  Remove-Item 'C:\pscript\vj\uniq.csv'
  
  
  $csv |
  Group-Object -Property ServerName |
  Where-Object -FilterScript {
  $_.Count -gt 1
  } |
  Select-Object -ExpandProperty Group| Export-Csv -Path 'C:\pscript\vj\dup.csv' -NoTypeInformation
  
  
  
  Import-Csv -Path 'C:\pscript\vj\dup.csv' | Group-Object ServerName | ForEach-Object {
  # replace the placeholders in the template. Sort the numeric values for neatness as we go.
  $template -replace '#Title#', (([int[]]$_.Group.IGPID | Sort-Object) -join ', ') -replace
  '#computername#', &quot;&lt;ComputerName&gt;$($_.Name)&lt;/ComputerName&gt;&quot; |
  Set-Content -Path &quot;C:\pscript\vj\$($_.Name).xml&quot; -Encoding UTF8
  }
  
  $csv |
  Group-Object -Property ServerName |
  Where-Object -FilterScript {
  $_.Count -lt 2
  } |
  Select-Object -ExpandProperty Group| Export-Csv -Path 'C:\pscript\vj\uniq.csv' -NoTypeInformation
  Import-Csv -Path 'C:\pscript\vj\uniq.csv' | Group-Object IGPID | ForEach-Object {
  # replace the placeholders in the template. Sort the numeric values for neatness as we go.
  $template -replace '#computername#',&quot;&lt;ComputerName&gt;$(($_.Group.ServerName) -join ',')&lt;/ComputerName&gt;&quot; -replace
  '#Title#', ($_.Name) |
  Set-Content -Path &quot;C:\pscript\vj\$($_.Name).xml&quot; -Encoding UTF8
  
   }
  </code></pre>
  <p>I am sure below part is handling this comma separation, please help in how to update it so it will not break or effect code 1 in the script.</p>
  <pre><code>$template -replace '#computername#',&quot;&lt;ComputerName&gt;$(($_.Group.ServerName) -join ',')&lt;/ComputerName&gt;&quot; -replace
  </code></pre>