You cannot use OleDB to delete data from an Excel document. According to MSDN docmentation:
Although the Jet OLE DB provider allows you to insert and update records in an Excel workbook, it does not allow you to work with DELETE
What you can do is use the Exel COM interface to delete lines. Remember to release COM . In this way,
$file = c:\temp\MyExcelFile.xls
$excel = new-object -com Excel.Application -Property @{Visible = $false}
$workbook = $excel.Workbooks.Open($file)
$sheet = $workbook.Sheets.Item(1)
[void]$sheet.Cells.Item(1, 1).EntireRow.Delete()
$workbook.Close($true)
$excel.quit()
[Runtime.Interopservices.Marshal]::ReleaseComObject($excel)
source
share