title: Create a count loop within XML and output
body: <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE xml&gt;
  &lt;/object&gt; -&lt;object type="host"&gt; 
  &lt;property value="4" name="id"/&gt; 
  &lt;property value="briu065a" name="name"/&gt; 
  &lt;property value="2" name="port_count"/&gt; 
  &lt;property value="generic" name="type"/&gt; 
  &lt;property value="11111111111111111111111111111111111" name="mask"/&gt;       
  &lt;property value="4" name="iogrp_count"/&gt; 
  &lt;property value="offline" name="status"/&gt; 
  &lt;property value="10000000C94EA2C9" name="WWPN"/&gt; 
  &lt;property value="0" name="node_logged_in_count"/&gt; 
  &lt;property value="offline" name="state"/&gt; 
  &lt;property value="10000000C94EC64E" name="WWPN"/&gt; 
  &lt;property value="0" name="node_logged_in_count"/&gt; 
  &lt;property value="offline" name="state"/&gt; 
  &lt;property value="10000000C94ECFEF" name="WWPN"/&gt; 
  &lt;property value="0" name="node_logged_in_count"/&gt; 
  &lt;property value="offline" name="state"/&gt; 
  &lt;/object&gt;
  &lt;object type="hostio_grp"&gt; 
  &lt;property value="4" name="host_id"/&gt; 
  &lt;property value="0" name="id"/&gt; 
  &lt;property value="iogrp_ab" name="name"/&gt; &lt;/object&gt;
  </code></pre>
  
  <p>Hi, I'm wondering if you can offer me some guidence here. I'm reading the above XML data and reporting out to a csv file. I am looking to take each value in the XML file and store it as an individual variable.</p>
  
  <p>For single entries under type="host" such as "name" and "mask" I can extract the value into an individual variable easily, but when there are multiple values with the same name such as "WWPN" I'm finding it difficult to capture these multiple entries into seperate variables. </p>
  
  <p>From the below code, I was hoping something like this would work:</p>
  
  <pre><code>if ($type -eq "host" -and $name -eq "WWPN" ) {$wwpn[$cnt] = $value.$cnt++
  add-content $hostinfo "$hname,$wwpn(1),$wwpn(2),$wwpn(3)"}
  </code></pre>
  
  <p>I would like the csv ouput to basically look like this:</p>
  
  <p>hname,    wwpn1,           wwpn2,           wwpn3
  briu065a    ,10000000C94EA2C9,10000000C94EC64E,10000000C94ECFEF</p>
  
  <p>I'm fairly new to Powershell, so any guidance would be much appreciated. Here is my code below:</p>
  
  <pre><code>$files = Get-ChildItem $XMLPath\*.xml
  foreach ($file in $files)
     {
     $xmlOutput=select-xml -path $file -XPath *
     foreach ($object in $xmlOutput.node.object)
         {
         $type=$object.type 
         foreach ($property in $object.property)
            {
            $name=$property.name
            $value=$property.value 
            if ($type -eq "host" -and $name -eq "name" ) {$hname = $value}
            if ($type -eq "host" -and $name -eq "WWPN" ) {$wwpn  = $value 
            add-content $hostinfo "$hname,$wwpn"}
            }     
         }
  </code></pre>