title: Replace multiple Strings with Data from CSV
body: <p>I've got a CSV (with headers) from all of our access points and want to add them to Zabbix via XML Upload.</p>
  
  <p>Since I don't want to create an XML file for each AP manually, I'll try to do this in PowerShell. But - how?</p>
  
  <p>I've tried some things with <code>(Get-Content .\Template.xml).Replace()</code> and <code>ForEach-Object</code>, but I haven't had success yet.</p>
  
  <p>Filenames are:</p>
  
  <ul>
  <li><p><code>AP.csv</code> (list of APs, headers are Hostname and IP):</p>
  
  <pre>Hostname;IP
  AP1;10.29.202.101
  AP2;10.29.202.102
  AP3;10.29.202.103
  AP4;10.29.202.104
  Ap5;10.29.202.105</pre></li>
  <li><p><code>Template.xml</code>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;hosts&gt;
    &lt;host&gt;
      &lt;host&gt;Hostname&lt;/host&gt;
      &lt;name&gt;Hostname&lt;/name&gt;
      [...]
      &lt;interfaces&gt;
        &lt;interface&gt;
          [...]
          &lt;ip&gt;PIIP&lt;/ip&gt;
          [...]
        &lt;/interface&gt;
        &lt;interface&gt;
  </code></pre>
  
  <p>The <code>Template.xml</code> has 2 strings Called "Hostname" and 2 Called "PIIP" - Both Hostname strings should be replaced with 1 Hostname from <code>AP.csv</code>, and both PIIP should be replaced with the related IP.</p></li>
  </ul>
  
  <p>My Last attempt so far was: </p>
  
  <pre class="lang-bsh prettyprint-override"><code>$a = Import-Csv .\Ap.csv
  $APHost = ($a).Hostname
  $APIP = ($a).IP
  $xml = Get-Content .\Template.xml
  foreach ($row in $a) {
      $xml.Replace('Hostname',$APHost).Replace('PIIP',$APIP) |
          Out-File ".\Aps\$row.xml"
  }
  </code></pre>
  
  <p>But this ended in all hostnames and all IPs where in 1 XML file.</p>
  
  <p>I would like to have 1 XML file for each host at the end with hostnames and related IP.</p>