【问题标题】:SSIS Powershell Pass result to VariableSSIS Powershell 将结果传递给变量
【发布时间】:2018-11-30 15:58:11
【问题描述】:

我有下面的 Powershell 脚本,它正在检查文件是否存在并被锁定。这是通过执行流程任务在 SSIS 中调用的。但是,我想将此结果作为“真”或“假”传递给 SSIS 中的变量(称为“Log_Result”,然后我可以将其用于优先约束。我将如何修改脚本以传递变量的真假?

# checks if the file exists and then if the file is locked

$file = "\\xxxx\xxxx\xxxxxxx\test.log"
if (Test-Path -path $file)
{ 
    try { [IO.File]::OpenWrite($file).close();exit 0 } catch { exit 999}
}
else
{
    exit 999
}

【问题讨论】:

  • 您是通过Execute Process Task 调用PS 脚本吗?如果没有,脚本是如何在 SSIS 中运行的?
  • 是 - 根据编辑
  • 您可以将Execute Process Task 配置为使用StandardOutputVariable。您可能还必须将FailTaskIfReturnCodeIsNotSuccessValue 设置为False

标签: powershell ssis


【解决方案1】:

当我希望 Powershell 通过将进程部分中的可执行文件设置为 Powershell.exe 并将参数设置为 @ 来返回一个存储在 SSIS 变量中的值时,我想出了解决执行进程任务中类似问题的解决方案987654326@ 其中test.ps1 是PowerShell 脚本的名称,$LastExitCode 是将值返回给SSIS,将StandardOutputVariable 设置为我创建的名为User::ReturnValue 的字符串变量,并将FailTask​​IfReturnCodeIsNotSuccessValue 更改为False,因为我正在测试各种值返回,在某些情况下返回的值与默认的 SuccessValue 不匹配:

有关参数部分的更多详细信息,-Command 告诉 Powershell.exe 要运行什么命令。 & 允许 Powershell 运行多个命令,{c:\test.ps1; $LastExitCode} 是要运行的命令。

在 test.ps1 脚本中,我将退出代码设置为返回 1 或 0。当程序包运行时,它会返回我在脚本中设置的代码,并将 \r\n 作为回车符附加到值后,换行 ( CRLF)并且我没有花额外的时间来修改值,这是我在 SSIS 中运行测试时的结果:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-19
    • 1970-01-01
    • 2015-01-14
    • 2023-01-02
    相关资源
    最近更新 更多