I am trying to run a TaskScheduler task on a Virtual Machine. The issue is, when I set the Security Options to "Run whether user is logged on or not," with the highest priviledges (Selected user account is an Domain Admin), the task fails. My PowerShell script writes a temporary XLSX file into a folder in the C: and promptly removes it after it is uploaded to a FTP site. I am getting permission issues where the remote computer cannot save files into the C:.
I spent hours Googling this issue and so far I've found no solid answers.
My TaskScheduler task is located within an admin account in the Virtual Machine. It does not fail when the security option is set to "Run only when user is logged on."
Does anyone have any ideas?
I attempted to remote in by enabling PSRemoting and using a separate machine with Admin credentials. Even then I am unable to create any excel files using the workbook.saveas() function.
I verbosed the messages I am receiving from my script.
Debug Log: 02/06/2015 14:31:19
C:\Users\SQLADMIN\Desktop
Exception calling "InvokeScript" with "1" argument(s): "Unable to save to
C:\Users\SQLADMIN\Desktop\FTP_MYS_Upload\ExhibitorCompaniesDetails.xlsx.
Please ensure you have write access."
At C:\Users\SQLADMIN\Desktop\FTP_MYS_Upload\Export-XLSX with Excel.ps1:168
char:13
+ $ExecutionContext.InvokeCommand.InvokeScript($Script)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : RuntimeException
Exception calling "InvokeScript" with "1" argument(s): "Unable to save to
C:\Users\SQLADMIN\Desktop\FTP_MYS_Upload\ExhibitorCompaniesExpoHistory.xlsx.
Please ensure you have write access."
At C:\Users\SQLADMIN\Desktop\FTP_MYS_Upload\Export-XLSX with Excel.ps1:168
char:13
+ $ExecutionContext.InvokeCommand.InvokeScript($Script)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : RuntimeException
The "Unable to save to DIR. Please ensure you have write access" is a try catch for the .saveas() method in my create XLSX script.
I can out-file remotely, essentially creating a txt document but I cannot use the .saveas() method. Any ideas? Does it have to do with Excel/Powershell?
Looks like its a dotNet issue. dotNet does not play nicely when it calls Excel remotely. I'll investigate further.
After two months of trying to figure out what the problem was.... I found an article on TechDecode.com...
http://www.techdecode.com/wp/?p=58
For the sake of continuity I will copy the text into here.
All I had to do was grant myself permissions to: C:\Windows\SysWOW64\config\systemprofile\Desktop
I hope this helps the next person.
Gotcha! – Office 2007 Automation with Powershell in Windows 2008
It seems MS has changed the game again on Office automations with Office 2007 and Windows 2008 and/or Windows 7 and Powershell scripts. I do quite a bit of Powershell scripting and found that after upgrading my script host to 2008 R2, my scripts scheduled in Task Manager no longer worked. I pulled out my hair for a few days trying all kinds of different things – changing paths, permissions, syntax – you name it, I tried it. I kept getting this error message –
Exception calling “SaveAs” with “1” argument(s): “SaveAs method of Workbook class failed”
After Googling for the hundreth time or so, I finally stumbled across this post on the Social MSDN Forums. I could not believe it that when I simply added a folder to the server, it all worked! This is the folder you need to add (Thank you H Ogawa for your posting!) – ・Windows 2008 Server x64 Please make this folder. C:\Windows\SysWOW64\config\systemprofile\Desktop
・Windows 2008 Server x86 Please make this folder. C:\Windows\System32\config\systemprofile\Desktop
Frustrating, but fixed!