title: Powershell COM Excel visible not working
body: <p>I have written a short Powershell script to copy some Excel data.  The script works fine, but it opens Excel every time I run it, even thought the visible property is set to $false. Anyone have any ideas why?  I have searched for answers, but can't find any solutions.  I have also displayed the property and it is set correctly.  </p>
  
  <p>Excel opens when the workbook is opened.  </p>
  
  <p>Thanks,</p>
  
  <p>Chris J.</p>
  
  <p>Code:</p>
  
  <pre><code>## function to close all com objects
  function Release-Ref ($ref{
  ([System.Runtime.InteropServices.Marshal]::ReleaseComObject([System.__ComObject]$ref)   -gt 0)
  [System.GC]::Collect()
  [System.GC]::WaitForPendingFinalizers()
  }
  #Read-Host -Prompt "Press Enter to exit"
  #####################################################################
  ## Load excel com objects attach to file
  #####################################################################
  $ExcelPath = 'C:\Chris_Test.xls'
  $Excel = New-Object -ComObject Excel.Application
  $Excel.Visible = $False
  write-host "Visible 1"
  write-host $Excel.Visible
  $ExcelWorkBook = $Excel.Workbooks.Open($ExcelPath)
  $Excel.Visible = $False
  write-host "Visible 2"
  write-host $Excel.Visible
  $ExcelWorkSheet = $Excel.WorkSheets.item("Sheet1")
  $Excel.Visible = $False
  write-host "Visible 3"
  write-host $Excel.Visible
  $row = 2
  $South_HX_Avg = "This"
  $Middle_HX_Avg = " is a "
  $North_HX_Avg = "test."
  ##
  ## Cells.Item(Row,Column)
  #$ExcelWorkSheet.Cells.Item($row,1).Value2 = $South_HX_Avg
  #$ExcelWorkSheet.Cells.Item(2,2).Value2 = $Middle_HX_Avg
  #$ExcelWorkSheet.Cells.Item(2,3).Value2 = $North_HX_Avg
  #####################################################################
  # Close connections to Excel
  # set interactive to false so no save buttons are shown
  #####################################################################
  $Excel.DisplayAlerts = $false
  $Excel.ScreenUpdating = $false
  $Excel.Visible = $False
  write-host "Visible 4"
  write-host $Excel.Visible
  $Excel.Visible = $false
  $Excel.Visible = $False
  write-host "Visible 5"
  write-host $Excel.Visible
  $Excel.UserControl = $false
  $Excel.Interactive = $false
  ## save the workbook
  $ExcelWorkBook.Save()
  ## quit the workbook
  $Excel.Quit()
  ## close all object references
  Release-Ref($ExcelWorkSheet)
  Release-Ref($ExcelWorkBook)
  Release-Ref($Excel)
  # Move-Item c:\scripts\test.zip c:\test -force
  Read-Host -Prompt "Press Enter to exit"
  </code></pre>