title: Extracting a link and save an attachment in it -- PowerShell
body: <p>Am trying to extract a link from a email's body and save the attachment in that link. </p>
  
  <pre><code>$Folder = "InBox"
  Add-Type -AssemblyName microsoft.office.interop.outlook
  $Outlook = New-Object -ComObject Outlook.Application
  $Namespace = $Outlook.GetNameSpace("MAPI")
  $Email = $NameSpace.Folders.Item(1).Folders.Item($Folder).Items
  $extracts = $Email | Where-Object {$_.subject -match "PITM*"}
  
  $extracts | ForEach-Object {
      $email = $_.Body 
      #$lines = $email | Measure-Object -Line
  
      if($email -match '&lt;(.*?)&gt;'){
       "Match Found"     
       $url = $matches[1]          
       }
       $url
       $output = "H:\foo.DAT"
  
      $Process = new-Object System.Diagnostics.Process
      $Process.StartInfo.WindowStyle="Hidden"
      $Process.StartInfo.FileName="chrome.exe"
      $Process.StartInfo.Arguments=$url
      $Process.Start()    
  
  }
          $Process.Dispose()         
  </code></pre>
  
  <p>Email body looks like this: </p>
  
  <blockquote>
    <p>Number: PITM0008575
    <a href="https://a.com/nav_to.do?uri=foo%3Fsys_id=58689b056f90a60002da186e6b3ee484%26sysparm_stack=u_production_item_list.do%3Fsysparm_query=active=true">https://a.com/nav_to.do?uri=foo%3Fsys_id=58689b056f90a60002da186e6b3ee484%26sysparm_stack=u_production_item_list.do%3Fsysparm_query=active=true</a></p>
    
    <p>Requested due date: </p>
    
    <p>Fulfilled date:</p>
    
    <p>Completed date:</p>
    
    <p>Attachments:  Report foo.txt
    <a href="https://a.com/sys_attachment.do?sys_id=829893456f90a60002da186e6b3ee402">https://a.com/sys_attachment.do?sys_id=829893456f90a60002da186e6b3ee402</a></p>
  </blockquote>
  
  <p>Here are the two issues I've:</p>
  
  <ol>
  <li>The script is not pulling up the second link.</li>
  <li>I'm not able to save the attachment that is a result of opening the link. </li>
  </ol>
  
  <p>Please help.     </p>