Я думаю, что Christian может работать, если вы установите для параметра DisplayAlerts значение $ false.
Попробуйте следующее, заменив путь:
$filePath = "path\to\excel.xslx" # replace filename
# function pulled from /6044513/kak-vyzvat-slozhnyi-com-metod-iz-powershell
# allows for calling complex COM object's methods... I can define which arguments I want to send in
Function Invoke-NamedParameter {
[CmdletBinding(DefaultParameterSetName = "Named")]
param(
[Parameter(ParameterSetName = "Named", Position = 0, Mandatory = $true)]
[Parameter(ParameterSetName = "Positional", Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[System.Object]$Object
,
[Parameter(ParameterSetName = "Named", Position = 1, Mandatory = $true)]
[Parameter(ParameterSetName = "Positional", Position = 1, Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]$Method
,
[Parameter(ParameterSetName = "Named", Position = 2, Mandatory = $true)]
[ValidateNotNull()]
[Hashtable]$Parameter
,
[Parameter(ParameterSetName = "Positional")]
[Object[]]$Argument
)
end { ## Just being explicit that this does not support pipelines
if ($PSCmdlet.ParameterSetName -eq "Named") {
## Invoke method with parameter names
## Note: It is ok to use a hashtable here because the keys (parameter names) and values (args)
## will be output in the same order. We don't need to worry about the order so long as
## all parameters have names
$Object.GetType().InvokeMember($Method, [System.Reflection.BindingFlags]::InvokeMethod,
$null, ## Binder
$Object, ## Target
([Object[]]($Parameter.Values)), ## Args
$null, ## Modifiers
$null, ## Culture
([String[]]($Parameter.Keys)) ## NamedParameters
)
} else {
## Invoke method without parameter names
$Object.GetType().InvokeMember($Method, [System.Reflection.BindingFlags]::InvokeMethod,
$null, ## Binder
$Object, ## Target
$Argument, ## Args
$null, ## Modifiers
$null, ## Culture
$null ## NamedParameters
)
}
}
}
# create Excel COM object, set to suppress alert boxes
$excelapp = new-object -com Excel.Application
$excelapp.displayalerts = $false
# open workbook with CorruptLoad = Repair
[void](invoke-namedparameter $excelapp.workbooks "Open" @{"Filename"=$filepath; "CorruptLoad"=2})
# save repaired file and close
$excelapp.activeworkbook.saveas($filepath)
$excelapp.quit()