title: Unable to Run Excel COM Object as SYSTEM
body: <p>I am trying to open, write, &amp; save an existing Excel file using PowerShell w/ COM Objects. I need to use the COM objects route because the existing Excel file uses formulas that the Import/Export-Excel PowerShell module does not honor. Excel 2016 is installed on the server &amp; the PowerShell script is being kicked off as SYSTEM.</p>
  <p>Code I have is:</p>
  <pre><code>$excel = New-Object -ComObject Excel.Application
  $excelWorkbook = $excel.Workbooks.Open($ServerBuildTrackingFilePath)
  $excelWorksheet = $excel.WorkSheets.item(&quot;VirtualServerBuild&quot;)
  $excelWorksheet.Activate()
  $xlDown = -4121
  $xlUp = -4162 
  $nextRow = ($excelWorksheet.cells.Range(&quot;A1048576&quot;).End($xlUp).row) + 1
  
  $excelWorksheet.Cells.Item($nextRow,1) = 'This'
  $excelWorksheet.Cells.Item($nextRow,2) = 'is a'
  $excelWorksheet.Cells.Item($nextRow,3) = 'Test'
  
  $excelWorkbook.Save()
  $excelWorkbook.Close()
  $excel.Quit()    
  [System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel) | Out-Null
  </code></pre>
  <p>Error returned is:</p>
  <pre><code>Microsoft Excel cannot access the file '\\domainfilepath\to\ServerBuildTracking.xlsx'. There 
  are several possible reasons:
  • The file name or path does not exist.
  • The file is being used by another program.
  • The workbook you are trying to save has the same name as a currently open workbook.
  At line:7 char:1
  + $excelWorkbook = $excel.Workbooks.Open($ServerBuildFilePath ...
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : OperationStopped: (:) [], COMException
      + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
  </code></pre>