I created a powershell script that reads from two different excel file and a few sheets within them and writes output to a new sheet in one of the two excel file. The script works perfectly fine from the a subdirectory under my desktop.
However, if I copy the script and the excel files to a folder under c:, the script does not run and locks the excel files as well.
Seems like some basic parameter initiation but couldn’t figure out.
The script must be running else it wouldn’t lock the files.
How is your logging? Sounds like you’re lacking some as well as not having the right try/catch statements. See if you can narrow it down a bit by sprinkling in some status statements to see how far the script progresses.
I think I found the issue. The script is locking the excel files and thus it becomes read-only. So, I am not able to write to a new sheet within the excel file.
As a remedy, I have changed the script to write the output to a new excel file and it works.
Now, the same script does not lock the file if I run it from a folder under my user home directory.