Refresh Excel dataset in SharePoint Online with PowerShell 403 error -


i have been attempting implement powershell script access excel workbook, check out, refresh dataset in workbook , check in again.

i've combined task in windows task scheduler run script daily server user account has access sharepoint online site.

my issue script not run. when view windows event logs can see getting 403 error

the script taken document found here document: link download document

the task gets following script , location of excel workbook arguments in action config of task (detailed in document above)

try { # creating excel com object  $xl = new-object -comobject excel.application;   # setting excel run without ui , without alerts $xl.displayalerts = $false;  $xl.visible = $false;  } catch { write-eventlog -eventid "5001" -logname "application" -message  "failed  start excel" -source "application" exit }  foreach ($i in $args) {  write-host "handling $i" try {     # allow update if can perform check out     if ($xl.workbooks.cancheckout($i))     {          # opening workbook, can local path or sharepoint url         $wb = $xl.workbooks.open($i);          # perform check out         $xl.workbooks.checkout($i)          # calling refresh         $wb.refreshall();          # saving , closing workbook         $wb.checkinwithversion();          # in case not using checkout/checkin perform save , close         #$wb.save();         #$wb.close();          #release workbook         [system.runtime.interopservices.marshal]::releasecomobject($wb)     }     else     {         write-host "check out failed for:  $i"         write-eventlog -eventid "5001" -logname "application" -message "workbook can't checked out $i" -source "application"     } } catch {     write-eventlog -eventid "5001" -logname "application" -message "failed refreshing workbook $i $_" -source "application"         }  }  #quiting excel $xl.quit();   #release excel [system.runtime.interopservices.marshal]::releasecomobject($xl) 

am missing here?

thanks in advance , please let me know if more info required.

edit: script works if run manually cmd correct arguments. problem seems task scheduler cannot access powershell.

so got working finally. issue wasn't running script when option 'user logged on or not' in general settings of task selected. worked fine when 'user logged on' selected.

here steps had take run properly.

first script needed run system32 folder (also specify directory in tasks "start in" box. make sure pointing 32-bit version of powershell since excel won't work 64-bit

and second, turns out there bug excel have create folder called “desktop” in \syswow64\config\systemprofile\ , \system32\config\systemprofile\ directories(both folders need created if running excel 64-bit).

this final argument string ended using: c:\windows\system32\windowspowershell\v1.0\powershell.exe -nologo –noprofile -noninteractive -executionpolicy bypass path\to\script 'path\to\excelworkbook'


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -