I use Invoke-Item "some-file.xlsx" to launch Excel and open a file. Now I would like to open this file in read only mode. It this possible from PowerShell?
To clearify, I am not looking to open the Excel sheet and read data from it to the PowerShell script, the script is intended to help the user finding a file and opening it.
Invoke-item only allows the default action for a file.
To open the file as read only, either:
Set read-only attribute on file, launch file, unset read-only attribute,
attrib +r "some-file.xlsx"
Invoke-Item "some-file.xlsx"
attrib -r "some-file.xlsx"
or
Invoke excel directly, and pass /r as the command file
$xl = (Get-ItemProperty -Path HKCR:\Applications\EXCEL.EXE\Shell\OpenAsReadOnly\command).'(default)'
$fle = '"some-file.xlsx"'
& $xl $fle
check Executing a Command stored in a Variable from Powershell to get a syntax that works for you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With