jantari / LSUClient

Orchestrate driver, BIOS/UEFI and firmware updates for Lenovo computers 👨‍💻
https://jantari.github.io/LSUClient-docs/
MIT License
208 stars 22 forks source link

Save-LSUpdate: file is being used by another process #77

Closed IT360BE closed 1 year ago

IT360BE commented 1 year ago

Version

1.5.2

Computer Model

20KKS36J00

Problem

Get-LSUpdate -Model "20KKS36J00" -All

throws:

TerminatingError(Get-FileHash): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: The file '\confidential\sds\SCCMSTORE\MDM\Lenovo\Offline-Updater\Cache\03.15.2023_19.27.28\20KKS36J00 z3wn11w z3wn11w.txt' cannot be read: The process cannot access the file '\confidential\sds\SCCMSTORE\MDM\Lenovo\Offline-Updater\Cache\03.15.2023_19.27.28\20KKS36J00 z3wn11w z3wn11w.txt' because it is being used by another process."

Additional context

Can you please try catch + skip the package in case of an error?

jantari commented 1 year ago

I could hide this error when it happens, but I don't like the idea of hiding errors from users - if something went wrong I believe you should know and be able find out what caused it.

This is not a terminating error, meaning that PowerShell prints the error but continues on with the next commands and packages.

The error you get says that you have configured ErrorActionPreference to Stop, which is not the default, and that is why for you it exits at the first error - no matter whether it is trivial or critical. Preference variables are documented here and you can also test this with an example script:

# Save this as test.ps1 and run it
Write-Output "Script begin - ErrorActionPreference is $ErrorActionPreference"
Get-FileHash -Path "$env:SystemDrive\pagefile.sys"
Write-Output "Script continued"

Despite Get-FileHash not being able to read this file and printing an error because of it, the script continues and the last output still happens. Only when you set $ErrorActionPreference = 'Stop' before running the example script above will it exit early.

I think you should run LSUClient with the default ErrorActionPreference of Continue, and when you run into any issues you may see some errors in your logs that could help you. Silencing or ignoring errors would not be beneficial I think.