首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SharePoint联机刷新Excel数据集与PowerShell 403错误

SharePoint联机刷新Excel数据集与PowerShell 403错误
EN

Stack Overflow用户
提问于 2015-08-19 13:21:56
回答 1查看 1.3K关注 0票数 1

我一直试图实现一个PowerShell脚本,它将访问一个Excel工作簿,签出它,刷新工作簿中的数据集,最后再签回它。

我将此与中的一个任务结合在一起,每天从具有访问SharePoint在线站点的用户帐户的服务器上运行脚本。

我的问题是脚本不会运行。当我查看Windows事件日志时,我可以看到它得到了一个403错误

这个脚本是从这里找到的文档中提取的:链接到下载文档

任务从任务操作配置中的参数获取以下脚本和Excel工作簿的位置(详见上面的文档)

代码语言:javascript
复制
try
{
# Creating the excel COM Object 
$xl = New-Object -ComObject Excel.Application; 

# Setting up Excel to run without UI and without alerts
$xl.DisplayAlerts = $false; 
$xl.Visible = $false; 
}
Catch
{
Write-EventLog -EventId "5001" -LogName "Application" -Message  "Failed  to start Excel" -Source "Application"
Exit
}

foreach ($i in $args)
{

write-host "handling $i"
try
{
    # Allow update only if we can perform check out
    If ($xl.workbooks.CanCheckOut($i))
    {

        # Opening the workbook, can be local path or SharePoint URL
        $wb = $xl.workbooks.open($i);

        # Perform the check out
        $xl.workbooks.checkout($i)

        # Calling the refresh
        $wb.RefreshAll();

        # Saving and closing the workbook
        $wb.CheckInWithVersion();

        # in case you are not using checkout/checkin perform a save and 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 be checked out $i" -Source "Application"
    }
}
catch
{
    Write-EventLog -EventId "5001" -LogName "Application" -Message "Failed refreshing the workbook $i $_" -Source "Application"        
}

}

#Quiting Excel
$xl.quit(); 

#Release Excel
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($xl)

我是不是漏掉了什么?

谢谢,如果需要更多的信息,请告诉我。

编辑:如果用正确的参数从cmd手动运行脚本,脚本就能工作。问题似乎在于任务调度程序无法访问PowerShell。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-28 05:57:54

所以我终于开始工作了。问题是,当选择任务的常规设置中的“用户登录与否”选项时,它没有运行脚本。当选择“用户登录”时工作正常。

这里是我必须采取的步骤,使它正常运行。

首先,脚本需要从System32文件夹中运行(还可以在任务“开始”框中指定该目录。此外,请确保您所指向的是32位版本的PowerShell,因为Excel不能使用64位。

其次,在Excel中有一个错误,您必须在\SysWOW64 64\config\systemprofile\和\System32 32\config\systemprofile\目录中创建一个名为“Desktop”的文件夹(如果运行Excel 64位,需要创建这两个文件夹)。

这是我最后使用的参数字符串: C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe -nologo -noprofile -noninteractive -executionpolicy绕开路径\to\script‘path\to\\excelworkbook’

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32096755

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档