title: Loading .msg file contents Using Powershell - Null Value error
body: <p>I am trying to access the metadata in a .msg file using Powershell (for example, get the sender address, subject line etc)</p>
  <p>I have the following, simple code</p>
  <pre><code>Add-Type -assembly &quot;Microsoft.Office.Interop.Outlook&quot;
  
  $outlook = New-Object -comObject Outlook.Application
  $msg = $outlook.Session.OpenSharedItem(&quot;C:\Test\email.msg&quot;)
  </code></pre>
  <p>but I get the error</p>
  <blockquote>
  <p>You cannot call a method on a null-valued expression. At line:4 char:1</p>
  </blockquote>
  <p>If I run</p>
  <pre><code>$outlook
  </code></pre>
  <p>I get</p>
  <pre><code>Application        : 
  Class              : 
  Session            : 
  Parent             : 
  Assistant          : 
  Name               : 
  Version            : 
  COMAddIns          : 
  Explorers          : 
  Inspectors         : 
  LanguageSettings   : 
  ProductCode        : 
  AnswerWizard       : 
  FeatureInstall     : 
  Reminders          : 
  DefaultProfileName : 
  IsTrusted          : 
  Assistance         : 
  TimeZones          : 
  PickerDialog       : 
  </code></pre>
  <p>all the properties appear to be null, including <code>.Session</code>, which explains why I get the null value error.</p>
  <p>What have I done wrong in creating the <code>$outlook</code> object?</p>
  <p>I have tried with both Outlook running and not running and the same happens.</p>
  <p>I have Office 365 installed and I'm using Powershell 5.1.19041.1320</p>