OCCU
asked on
Using a PowerShell script to refresh an Excel Document through Windows Task Scheduler
I have written a simple Windows PowerShell script that opens an existing Excel document and refreshes all the data contained within;
$app = New-Object -comobject Excel.Application
$app.Visible = $True
$wb = $app.Workbooks.Open("C:\ba tch\Test.x lsx")
$wb.Name
$wb.RefreshAll()
$wb.Save()
$wb.Close()
$app.Quit()
When I run this script from Windows PowerShell ISE it works just fine, when I right click the .ps1 file and select Run with PowerShell it also works just fine. When I set this script to run in Windows task scheduler and select 'Run only when user is logged on' I'm able to successfully run it from Windows Task Scheduler. However, when I select 'Run whether user is logged on or not' it no longer runs, even if I select 'Run with highest privileges'.
Ideally I would like for this script to run regardless of whether anyone is signed on to this server, but doing some online research it seems like it is well documented that this is a difficult task to accomplish.
My online research did yield the following solution, that if I create these two foldesr;
C:\Windows\System32\config \systempro file\Deskt op
c:\windows\syswow64\config \systempro file\deskt op
it should allow the script to succeed, however, this has not seemed to work for me. Any advice or guidance would be most appreciated. Thanks in advance!
$app = New-Object -comobject Excel.Application
$app.Visible = $True
$wb = $app.Workbooks.Open("C:\ba
$wb.Name
$wb.RefreshAll()
$wb.Save()
$wb.Close()
$app.Quit()
When I run this script from Windows PowerShell ISE it works just fine, when I right click the .ps1 file and select Run with PowerShell it also works just fine. When I set this script to run in Windows task scheduler and select 'Run only when user is logged on' I'm able to successfully run it from Windows Task Scheduler. However, when I select 'Run whether user is logged on or not' it no longer runs, even if I select 'Run with highest privileges'.
Ideally I would like for this script to run regardless of whether anyone is signed on to this server, but doing some online research it seems like it is well documented that this is a difficult task to accomplish.
My online research did yield the following solution, that if I create these two foldesr;
C:\Windows\System32\config
c:\windows\syswow64\config
it should allow the script to succeed, however, this has not seemed to work for me. Any advice or guidance would be most appreciated. Thanks in advance!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It seems to be working now!
https://community.spiceworks.com/how_to/17736-run-powershell-scripts-from-task-scheduler