Powershell Excel Automation – Save/Open fails in Scheduled Task

Question:

I created a simple powershell script that will create an excel instance and save a workbook:

When I run this from powershell directly it works fine.
I created a scheduled task that runs it, and when I have the option set that will “Run only when the user is logged in” then it will run fine.

When I change this option to run whether the user is logged in or not, it will fail trying to open/save the file. The account I am using has the correct permissions. I have the account set up to Log in as a service.

Any suggestions?

Answer:

I remember having to do something similar in a C# application, which went well when you build it on Visual Studio, but running under a service on the CI server failed. This I believe is the limitation of Office Automation itself and Microsoft doesn’t recommend / support doing this at all Look at Considerations for server-side Automation of Office here – http://support.microsoft.com/kb/257757. It shows the problems and the alternatives.

In my case, I had to give up Office Interop, and use EPPlus ( http://epplus.codeplex.com/ ) to work with excel. It worked great and was much faster as well.

Source:

Powershell Excel Automation – Save/Open fails in Scheduled Task by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply