我已经对如何从SSIS运行参数化的PS脚本做了大量的研究。我遇到了运行参数化脚本的问题。 PS脚本如下,如果我硬编码参数到它的行为与预期的脚本:通过SSIS执行参数化的powershell脚本执行进程任务(使用UNC)
Param ([string]$filepath,[string]$filename)
$Path = $filepath
$InputFile = (Join-Path $Path $filename)
$Reader = New-Object System.IO.StreamReader($InputFile)
While (($Line = $Reader.ReadLine()) -ne $null) {
If ($Line -match 'FILE\|([^\|]+)') {
$OutputFile = "$($matches[1]).txt"
}
Add-Content (Join-Path $Path $OutputFile) $Line
}
运行在SSIS执行过程中的任务,我想通过表达来构建Arguments
命令如下:
"-ExecutionPolicy ByPass -File " + @[User::vPSScriptLocation] + " " + @[User::vFilePath]+ " "+ @[User::vFileName]
计算表达式给出如下:
-ExecutionPolicy ByPass -File \\WorkDirectory\Script.ps1 \\transfer datafile.data
在执行时,任务失败。该名为.ps1从工作目录中删除,SSIS提供了以下错误代码:
Error: 0xC0029151 at Execute powershell script, Execute Process Task: In Executing "C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe" "-ExecutionPolicy ByPass -File \\WorkDirectory\Script.ps1 \\transfer datafile.data" at "", The process exit code was "-196608" while the expected was "0".
看起来像是得到一个空字符串,它不应该?任何指针赞赏。
所以你的进程应该读取文件“\\传输\ datafile.data “?这不是一个有效的UNC路径。如果您运行错误中显示的代码,您的脚本是否可以正常工作?它看起来像它将所有参数作为一个字符串传递,但这可能只是如何写入错误。将不得不检查'-File'是否支持UNC。 [这个问题](http://stackoverflow.com/questions/35729192/ssis-powershell-script-execute)得到你的错误试图使用UNC路径的文件。 – Matt
它应该读取\\ WorkDirectory \ Script.ps1,它又不是UNC。我也尝试在语音标记中传递参数,但得到相同的结果。它可能是UNC,尽管它非常奇怪的行为是从读取位置删除ps1文件。 – TJB
“\\ WorkDirectory \ Script.ps1”不是一个有效的路径,所以我认为powershell不知道你想要运行什么。这应该是一个相对路径或什么?我敢打赌你没有一个名为WorkDirectory的服务器,这是PowerShell将要寻找的。在您的脚本中应该发生同样的问题,这正是我在尝试指出的那种情况下建立的类似路径无效的情况。 – Matt