excel - Powershell 使用 OLAP 查询刷新 Excel。凭证问题
问题描述
我对 PowerShell 脚本比较陌生,所以请耐心等待我:)
我有多个带有连接到 Power BI 数据集的 OLAP 查询连接的 excel 文件,以下是脚本;
$libraryPath = "C:\Repos\AUSD\3.0\Test"
$excel = new-object -comobject Excel.Application
$excel.Visible = $false
# Give delay to open
Start-Sleep -s 3
$allExcelfiles = Get-ChildItem $libraryPath -recurse -include “*.xls*”
foreach ($file in $allExcelfiles)
{
$workbookpath = $file.fullname
Write-Host "Updating " $workbookpath
# Open the Excel file
$excelworkbook = $excel.workbooks.Open($workbookpath)
$connections = $excelworkbook.Connections
# This will Refresh All the pivot tables data.
$excelworkbook.RefreshAll()
# The following script lines will Save the file.
$excelworkbook.Save()
$excelworkbook.Close()
Write-Host "Update Complete " $workbookpath
}
$excel.quit()
如果遵循选项,它工作正常;$excel.Visible 为真
然而,这将在服务器中安排,希望这可以在后台完成,因此 $excel.Visible = $false
这导致以下错误;
我怀疑这是由于 Excel 打开时发生的自动登录,由于它没有打开,它在登录过程中失败。
如何绕过或更确切地说设置凭据/权限?
解决方案
推荐阅读
- python - 将两个列表合并为一个 - python
- c# - 无法将对象从 DBNull 转换为具有输出参数的存储过程中的其他类型
- javascript - 单击禁用按钮时,如何使模式出现?
- r - 使用 rvest 进行网页抓取适用于网站的第一页,但不适用于其他网页
- ios - NEHotspotConfigurationErrorDomain Code=5“无效的 EAP 设置。”
- java - 批处理 4.0.1 - 作业开始但 jobParametersValidator 为空
- java - 查找与 JSON 中特定键值对匹配的给定格式的正则表达式
- powerbi - Power bi - 无法在 Power bi 服务器中为 Web 匿名连接设置刷新
- spring - 我正在尝试删除列表中的子元素
- python - x 和 y 之间的 NoForeignKeysError