title: Finding a CID reference for attachments in Exchange Contacts
body: <p>I'm crafting a powershell program using EWS that:</p>
  
  <ul>
  <li>Recover some data from a backup contact folder (telephone, url, notes field,...)</li>
  <li>Set back those values in default contact folder in the new contact</li>
  </ul>
  
  <p>Everything does work except, of course, attachents that were added to notes fields, still i'm able to download them.</p>
  
  <pre><code>        foreach ($attch in $Item.Attachments)
          {
              $downloadDirectory = ".\attachments"
              $attch.Load()
              $fiFile = new-object System.IO.FileStream(($downloadDirectory + “\” + $attch.Name.ToString()), [System.IO.FileMode]::Create)
              $fiFile.Write($attch.Content, 0, $attch.Content.Length)
              $fiFile.Close()
              write-host "Downloaded Attachment : " + (($downloadDirectory + “\” + $attch.Name.ToString())) 
  
          }
  </code></pre>
  
  <p>Or upload them. (it's static here for test purpose)</p>
  
  <pre><code>$att = $item.Attachments.AddFileAttachment("C:\Scripts\myscript\attachments\PowerShell_transcript.20140506143510.txt")
  $att.ContentId = 'test'
  $att.IsInline=$false
  </code></pre>
  
  <p>Ideally, i was looking for matching CID references and uplading back attachments using the same one.</p>
  
  <pre><code>    &lt;div&gt;&lt;font face="Calibri" size="2"&gt;&lt;span style="font-size:11pt;"&gt;
  &lt;img src="cid:0DF540471453B832E300400FF03B0900CFEC1201@1"&gt; 
      &lt;a href="cid:74D8EEA6180AD131B48DC59373FABBABD7E361BB@1"&gt;SomeDoc.docx&lt;/a&gt;
      &lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Of course, when the object retrieved from exchange, it doesn't have a contentid (I would have guess it should be CID value).</p>
  
  <pre><code>&lt;Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"&gt;
    &lt;Obj RefId="0"&gt;
      &lt;TN RefId="0"&gt;
        &lt;T&gt;Microsoft.Exchange.WebServices.Data.FileAttachment&lt;/T&gt;
        &lt;T&gt;Microsoft.Exchange.WebServices.Data.Attachment&lt;/T&gt;
        &lt;T&gt;Microsoft.Exchange.WebServices.Data.ComplexProperty&lt;/T&gt;
        &lt;T&gt;System.Object&lt;/T&gt;
      &lt;/TN&gt;
      &lt;ToString&gt;Microsoft.Exchange.WebServices.Data.FileAttachment&lt;/ToString&gt;
      &lt;Props&gt;
        &lt;Nil N="FileName" /&gt;
        &lt;BA N="Content"&gt;&lt;/BA&gt;
        &lt;B N="IsContactPhoto"&gt;false&lt;/B&gt;
        &lt;S N="Id"&gt;AAMkADdmMDBkOTk4LTNlYzMtNDk1MS05ZTdhLWJmOGE.....&lt;/S&gt;
        &lt;S N="Name"&gt;SomeDoc.docx&lt;/S&gt;
        &lt;S N="ContentType"&gt;application/vnd.openxmlformats-officedocument.wordprocessingml.document&lt;/S&gt;
        &lt;Nil N="ContentId" /&gt; &lt;=== WHERE IS MY VALUE :'(
        &lt;Nil N="ContentLocation" /&gt;
        &lt;I32 N="Size"&gt;1764632&lt;/I32&gt;
        &lt;DT N="LastModifiedTime"&gt;2016-01-26T15:08:03+00:00&lt;/DT&gt;
        &lt;B N="IsInline"&gt;false&lt;/B&gt;
      &lt;/Props&gt;
    &lt;/Obj&gt;
  &lt;/Objs&gt;
  </code></pre>
  
  <p>Does someone know a way to retrieve that value ?</p>
  
  <ul>
  <li>Server/mailbox: Exchange 2013 SP1</li>
  </ul>
  
  <p>Thank you !</p>