How can I bypass this Powershell warning message?

Viewed 531

I have always used this script to open an Excel workbook automatically, save it and use it. Since the workbook has been modified the script does not work, because every time I open the file a popup appears that warns me that there are errors inside the workbook.

How can I bypass this problem and make Powershell press the "ok" button in the warning message to continue with the update?

enter image description here

$file = 'C:\Users\User\Desktop\SPC_Analysis_v2.3 - 36 mesi_250_macchine_IPC - Copia - Copia.xlsm' 
$x1 = New-Object -ComObject "Excel.Application"
$x1.Visible = $false                
$enddate = (Get-Date).tostring("dd-MM-yy HH-mm-ss")  
$filename = 'C:\Users\User\Desktop\SPC\IPC\IPC_QCP - Copia ' + $enddate + '.xlsm' 
$wb = $x1.workbooks.Open($file) 
$wb.RefreshAll() 
$wb.SaveAs($filename) 
$wb.Close() 
$x1.Quit() 
Remove-Variable wb,x1
1 Answers
Related