title: How to dynamically add new properties to custom object in PowerShell
body: <p>I have a custom object that contains device information that looks something like this.</p>
  
  <pre><code>name,model,sn
  PC1,Elitebook 850, ABC123,
  PC2,EliteDesk 600,123ABC
  </code></pre>
  
  <p>I have a function that retrieves threats detected by an antivirus product. These are returned as an array of objects. There are more properties than below but this is just an example</p>
  
  <pre><code>file,md5
  bad.exe,adfdfdfd
  evil.exe,fdfdffdf
  </code></pre>
  
  <p>I would like to add each member as properties to the custom object so the final output is similar to this.</p>
  
  <pre><code>name,model,sn,01_file,01_md5,02_file,02_md5
  </code></pre>
  
  <p>Currently, my script does this:</p>
  
  <pre><code>foreach($device in $devices){
      $threats = Get-Threats $device
      [pscustomobject] @{
          name = $device.device_name
          make = $device.make
          sn = $device.sn
          ThreatFileName = $threats.File -join ", "
          Threat_md5 = $threats.md5 -join ", "
      }
  }
  </code></pre>
  
  <p>This works ok but I'd really like each object returned by the 'Get-Threats' function to be listed as its own set of properties. I need this to be generated dynamically because I don't know how many threats will be returned for each device. </p>
  
  <p>Any thoughts on how to go about this?</p>