Sql server 通过Visio中的Powershell脚本自动刷新SQL Server导入的数据集
我目前正在尝试编写Powershell脚本,可用于刷新Visio文件中的数据并将结果导出为pdf。我遇到的问题是DataRecordset.Refresh方法似乎会在允许脚本完成之前导致弹出凭证条目。这有什么办法吗Sql server 通过Visio中的Powershell脚本自动刷新SQL Server导入的数据集,sql-server,powershell,refresh,visio,Sql Server,Powershell,Refresh,Visio,我目前正在尝试编写Powershell脚本,可用于刷新Visio文件中的数据并将结果导出为pdf。我遇到的问题是DataRecordset.Refresh方法似乎会在允许脚本完成之前导致弹出凭证条目。这有什么办法吗 $floorplans = Get-ChildItem -Filter "*.vsdx" Write-Host "Converting Visio documents to PDF..." -ForegroundColor Cyan try
$floorplans = Get-ChildItem -Filter "*.vsdx"
Write-Host "Converting Visio documents to PDF..." -ForegroundColor Cyan
try
{
$visio = New-Object -ComObject Visio.Application
$visio.Visible = $false
foreach ($floorplan in $floorplans)
{
$pdfname = [IO.Path]::ChangeExtension($floorplan.FullName, '.pdf')
Write-Host "Converting:" $floorplan.FullName "to" $pdfname
$document = $visio.Documents.Add($floorplan.FullName)
foreach($dataSet IN $document.DataRecordSets())
{
$dataSet.Refresh()
}
# Export all pages to PDF, see constants here http://msdn.microsoft.com/en-us/library/office/ff766893.aspx
$document.ExportAsFixedFormat(1, $pdfname, 1, 0)
}
}
catch
{
Write-Error $_
}
finally
{
if ($visio)
{
$visio.Quit()
}
}
如果数据源需要身份验证(凭据),则需要指定这些凭据或将其保存在Visio文件中。通常在“数据库连接”页面上有一个复选框,允许将凭据保存在文件(在Visio中)中,具体取决于您的数据库类型 此外,您还可以尝试通过更改连接字符串来指定密码,如下所示:
$cs= $dataSet.DataConnection.ConnectionString
$dataSet.DataConnection.ConnectionString = "$cs;password=<your password>"
$dataSet.Refresh()
$cs=$dataSet.DataConnection.ConnectionString
$dataSet.DataConnection.ConnectionString=“$cs;密码=”
$dataSet.Refresh()
这是一篇相关的博客文章,请查看:
请注意,您可能需要不同的语法,具体取决于您使用的数据库。如您所述。这不是PowerShell代码问题,而是Visio互操作问题。如果该Visio已配置为需要密码,则必须提供凭据。因此,您需要使用sendkeys或其他GUI自动化工具(如AutoIT)。您知道如何配置visio以保存凭据,而不在刷新时请求凭据吗?这感觉就像是拼图中缺失的一块。我之所以将其作为powershell问题提出,是因为我认为可能需要将Refresh与其他东西结合使用。从未真正尝试过,所以我没有想过。一旦你进入COM,一切都是COM,而不是真正的PowerShell。做这个刷新就是调用任何需要的东西,如果涉及auth,那么如果不改变请求它的内容,就无法绕过它。因此,如果Visio正在调用其他东西来获取内容,那么其他东西可能是导致此auth提示一致的原因。非常感谢!这正是我要找的