在SSIS包中执行Powershell脚本

时间:2017-05-24 20:24:32

标签: powershell ssis

Powershell脚本访问网站,获取一些信息并将其写入平面文件。 如果我在Powershell中运行脚本它可以很好地工作,但是当我从SQL Server Agent运行它时,它会失败。 我已经在服务器中向运行包的SQL Server代理用户提供了读/写权限。 我也尝试过创建一个Step Type:PowerShell,然后从作业中运行脚本;操作系统(CmdExec)使用文件名作为参数来执行powershell命令;操作系统(CmdExec)运行调用Powershell脚本的批处理文件。

这是powershell脚本:

$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible= $false
$ie.Navigate("https://www.frbservices.org/EPaymentsDirectory/fpddir.txt")
while ($ie.Busy -eq $true){Start-Sleep -seconds 1;}
$Link=$ie.Document.getElementsByTagName("button") | where-object {$_.value -eq "Agree"}
If($Link){
    $Link.click()
}
while ($ie.Busy -eq $true){Start-Sleep -seconds 1;}
$destination = ".\FDRTestFile\FDRFile.txt"
$content = (@($ie.Document.getElementsByTagName("pre"))[0].innerText | Out-
File $destination)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($ie)
Remove-Variable ie

我在工作完成时收到此错误:

  

New-Object:由于以下错误,从IClassFactory创建具有CLSID {0002DF01-0000-0000-C000-000000000046}的COM组件实例失败:80004005未指定错误(来自HRESULT的异常:0x80004005(E_FAIL)) 。在D:\ SSIS \ FDR \ DownloadFDRFile.ps1:1 char:7 + $ ie = New-Object -ComObject' internetExplorer.Application' + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo:ResourceUnavailable:(:) [New-Object] COMExcept ion + FullyQualifiedErrorId:NoCOMClassIdentifiedMicrosoft.PowerShell.Comman ds.NewObjectCommandProperty' Visible'在这个对象上找不到;确保它存在且可设置。在D:\ SSIS \ FDR \ DownloadFDRFile.ps1:3 char:1 + $ ie.Visible = $ true + ~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidOperation :(: )[] RuntimeException + FullyQualifiedErrorId:PropertyNotFound您无法在空值表达式上调用方法。在D:\ SSIS \ FDR \ DownloadFDRFile.ps1:4 char:1 + $ ie.Navigate(" https://www.frbservices.org/EPaymentsDirectory/fpddir.txt")+ ~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ + CategoryInfo:InvalidOperation:(:) [] RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull您不能在空值表达式上调用方法。在D:\ SSIS \ FDR \ DownloadFDRFile.ps1:8 char:1 + $ Link = $ ie.Document.getElementsByTagName(" button")| where-object {$ _。value -eq" ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidOperation :( :) [] RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull You无法在空值表达式上调用方法。在D:\ SSIS \ FDR \ DownloadFDRFile.ps1:17 char:15 + $ content =(@($ ie.Document.getElementsByTagName(" pre"))[0] .innerText | Out-File。 .. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidOperation :(: )[] RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull异常调用" ReleaseComObject"使用" 1"参数:"对象引用未设置为对象的实例。&#34 ;在D:\ SSIS \ FDR \ DownloadFDRFile.ps1:18 char:1 + [System.Runtime.Interopservices.Marshal] :: ReleaseComObject($ ie)+ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo :NotSpecified:(:) [] MethodInvocationException + FullyQualifiedErrorId:NullReferenceException Remove-Variable:找不到名称为'的变量'。在D:\ SSIS \ FDR \ DownloadFDRFile.ps1:19 char:1 + Remove -Variable ie + ~~~~~~~~~~~~~~~~~~ + CategoryInfo:ObjectNotFound :(即:字符串) [Remove-Variable] I temNotFoundException + FullyQualifiedErrorId:VariableNotFoundMicrosoft.PowerShell.Commands.R emoveVariableCommand。处理退出代码0.步骤成功。,00:00:02,0,0 ,,,, 0

为什么会发生这种情况?

0 个答案:

没有答案