title: Gracefully closing a process in a remote Session
body: <p>I'm currently working on a little PowerShell Script to reset a users Outlook Profile on a remote machine. </p>
  
  <p>Before the necessary profile stuff can be done I want to check if Outlook is already running on the remote machine and, if it is, stop it gracefully. I don't want to kill the process so it can do its necessary clean-up and syncing.</p>
  
  <p>When I connect to the machine with an Administrative User and execute the following commands:</p>
  
  <pre><code>Enter-PSSession $remoteMachine
  $outlookProcess = Get-Process outlook
  $outlookProcess.CloseMainWindow()
  </code></pre>
  
  <p>I ontly get</p>
  
  <pre><code>False
  </code></pre>
  
  <p>as a "return Value"</p>
  
  <p>Killing the Process with:</p>
  
  <pre><code>Stop-Process $outlookProcess
  </code></pre>
  
  <p>works.</p>
  
  <p>The Process im trying to close was not started by the Administrative user im connecting with, so at first i thougth maybe I'm not allowed to manipulate in this users context, but if I do the same thing on my local machine (Starting the process with a "normal" user and then using CloseMainWindow() with an Administrative user) it closes the Process without any problems.</p>
  
  <p>So my question is how would I close this remote process gracefully?</p>