I'm having an issue with Powershell 3.0 saving an Excel 2013 file. My script opens an existing Excel file, adds data to the next free row before saving the file and sending it via email as an attachment. No matter what I try the Excel process stays open, if I kill the process the script runs the next time I execute it but does not add any data.
Based on other threads I tried the following:
$file="c:\scripts\mbx_connections.xlsx"
$xl=New-Object -ComObject "Excel.Application"
$wb=$xl.Workbooks.Open($file)
$ws=$wb.ActiveSheet
$xl.DisplayAlerts = $FALSE
$cells=$ws.Cells
$rows = $ws.UsedRange.Rows.Count
<snip>
$wb.SaveAs("c:\scripts\mbx_connections.xlsx")
$wb.Close()
$xl.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($wb)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($xl)
Remove-Variable wb
Remove-Variable xlAre there any other ways to close the file or known issues with using Excel 2013?