在PowerShell脚本中使用refreshall方法不刷新Excel

时间:2017-06-29 10:00:14

标签: excel powershell

我有PowerShell脚本,可以从SharePoint刷新Excel以共享驱动器位置。我通过.bat文件传递凭据,但是当我使用$excelworkbook.RefreshAll()方法并提示再次输入凭据时,凭据不会传递给Excel。 IF 我从refreshall中删除了括号,然后脚本将运行,但它没有刷新工作表数据。

我们将非常感谢您的帮助 问候,
拉朱

$excel = new-object -comobject Excel.Application

$excel.visible = $true

$fname = Split-Path $workbookpath -Leaf

storedp "$destpath" "Refreshing workbook"

$tempPath = "c:Temp\Autosys"
Copy-Item "$workbookpath" "$tempPath"
$excelworkbook = $excel.workbooks.Open("$tempPath\$fname")   
$excelworkbook.RefreshAll()  


while ($excelworkbook.ODBCConnection.Refreshing)
{
  Start-Sleep -Seconds 1
}

$excelworkbook.save()
$excelworkbook.close()
$excel.quit()
$DSN = $args[0]
$DB = $args[1]
$DB_User = $args[2]
$DB_Password = $args[3]
$SQLServerPwd = $args[4]
$NetworkPwd = $args[5]
$SingleOrBulk = $args[6]
$Filename = $args[7]
$OutFilename = $args[8]
$Dated = $args[9]
$DateFormat = $args[10]
write-host "DSN = $DSN"
write-host "DB = $DB"
write-host "DB_User = $DB_User"
write-host "DB_Password = $DB_Password"
write-host "SQLServerPwd = $SQLServerPwd"
write-host "NetworkPwd = $NetworkPwd"
write-host "SingleOrBulk = $SingleOrBulk"
write-host "Filename = $Filename"
write-host "OutFilename = $OutFilename"
$pass= $NetworkPwd | ConvertTo-SecureString -AsPlainText -Force   
$cred=New-Object System.Management.Automation.PSCredential('test@prod',$pass)
New-PSDrive -Name P -PSProvider FileSystem -Root "\\testprod.md.net\GroupShares\Global\PA" -Credential $cred

$cred=New-Object System.Management.Automation.PSCredential('test@dev',$pass)

1 个答案:

答案 0 :(得分:0)

我已通过在本地连接标签中将连接详细信息放在Internet Explorer中解决了我的问题。