title: How to attach files to a Powershell function and send it through MS Outlook?
body: <p>I've got this code:</p>
  
  <pre><code>Function Mailer ($MSubject, $MBody, $File){
  $Outlook = New-Object -ComObject Outlook.Application
  $Mail = $Outlook.CreateItem(0)
  $Mail.To = "abc@contoso.com"
  $Mail.Subject = $MSubject
  $Mail.Body = $MBody
  $Mail.Attachments.Add($File)
  $Mail.Send()
  }
  </code></pre>
  
  <p>I will work if I provide the exact path in the function by assigning it to the $File variable. However, I wish to make this universal for different subjects, bodies and paths. Shall I set the file path as global? What are your thoughts?</p>
  
  <p>Thanks in advance :)
  Piotr</p>