We help IT Professionals succeed at work.

Powershell Script with Excel can't be launched from Windows Schedule Task

Medium Priority
75 Views
Last Modified: 2020-01-24
Hi,

I have created a Powershell which use Excel:

$Excel = new-object -comobject excel.application
$book = $Excel.Workbooks.Open($Excelfile)



The PowerShell script works but not when it's running from Windows Schedule Task. Why? I'm launch on Windows 2012.
Comment
Watch Question

Mauro CazabonnetSenior Windows Automation Developer
CERTIFIED EXPERT
Top Expert 2015

Commented:
Just curious have you tried to run your script in non-interactive mode

Please take a look at this

https://stackoverflow.com/questions/9738535/powershell-test-for-noninteractive-mode

M
Sam JacobsCitrix Technology Professional / Director of TechDev Services, IPM
CERTIFIED EXPERT

Commented:
What if you add:
$excel.Visible = $False

Open in new window

before you open the workbook?
Brian BEE Topic Advisor, Independant Technology Professional
CERTIFIED EXPERT

Commented:
Is the task running with different permissions besides your own? Also if it referring to any network paths, they have to use UNC and not mapped drive letters.
Chinmay PatelChief Technology Ninja
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
I ran into similar issues while running Excel from a windows service, in the end I had to provide interactive account (service account did not work - no matter what permissions were given).

Author

Commented:
For your info, I did this and it works! You have to create both folders even if you are using 64 bits or just 32 bits:

Create these two folders:

32Bit:

C:\Windows\System32\config\systemprofile\Desktop  
64Bit:

C:\Windows\SysWOW64\config\systemprofile\Desktop
Commented:
Create these two folders:

32Bit:

C:\Windows\System32\config\systemprofile\Desktop  
64Bit:

C:\Windows\SysWOW64\config\systemprofile\Desktop
Chinmay PatelChief Technology Ninja
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:

Good Find :)

Mauro CazabonnetSenior Windows Automation Developer
CERTIFIED EXPERT
Top Expert 2015

Commented:
Agreed, good to know!!