title: Close excel application using Powershell
body: <p>I am initiating a macro in a workbook from powershell (to automate a process). The below in powershell opens the excel workbook and runs the macro without visualizing the process. </p>
  
  <p>The issue is even though I do not see the macro running, the new instance of excel generated from the macro is still open.</p>
  
  <pre><code># start Excel
  $excel = New-Object -comobject Excel.Application
  
  #open file
  $FilePath = 'C:\file\Book1.xlsm'
  $workbook = $excel.Workbooks.Open($FilePath)
  
  
  #access the Application object and run a macro
  $app = $excel.Application
  $app.Run("macro")
  
  
  #close excel
  [System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)
  Start-Sleep 1
  'Excel processes: {0}' -f @(Get-Process excel -ea 0).Count
  Remove-Variable $excel
  
  exit $LASTEXITCODE
  </code></pre>
  
  <p>The excel file still comes up as a process in task manager and is taking up memory space. </p>
  
  <p>How do I have powershell completely close the instance of the excel application that opens through the macro?</p>
  
  <p><a href="https://i.stack.imgur.com/mjLKx.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mjLKx.jpg" alt="enter image description here"></a></p>
  
  <p>Any help greatly appreciated!</p>