【问题标题】:Command is running fine in console but not when used by Powershell命令在控制台中运行良好,但在 Powershell 使用时运行良好
【发布时间】:2019-05-01 05:15:26
【问题描述】:

我有一个应该将项目部署到我的 SSIS 服务器的 PS 脚本。 当我在控制台中运行生成的命令时,它运行良好,但是当从 Powershell 执行命令时,由于此(Windows)错误而失败:

标题:SQL Server 集成服务

路径格式无效。 参数名称:DestinationPath (ISDeploymentWizard)

其他信息:

路径格式无效。 (Microsoft.SqlServer.IntegrationServices.Wizard.Common)

如果我从控制台运行生成的命令,它运行良好:

D:\Deploy\ISDeploymentWizard.exe /Silent /ModelType:Project /SourcePath:"D:\Deploy\Receive\My_Beautiful_Project.ispac" /DestinationServer:"localhost" /DestinationPath:"/SSISDB/My Beautiful Project/My_Beautiful_Project" /ProjectPassword:"SuperSecretPassword"

脚本(感谢 Guenther Schmitz 和 Janne Tukaanen 的建议):

#region script configuration
$SsisServer = "."
$ProjectFileFolder = "D:\Deploy\Receive"
$ProjectFileName = "My_Beautiful_Project.ispac"
$ProjectFilePassword = "SuperSecretPassword"
$FolderName = "My Beautiful Project"
$ProjectName = "My_Beautiful_Project"
$ISDeploymentWizard = "D:\Deploy\ISDeploymentWizard.exe"
#endregion

#region project deployment
# Create command line arguments
$DestinationPath = "/SSISDB/" + $FolderName + "/" + $ProjectName
$ProjectFilePath = $ProjectFileFolder + "\" + $ProjectFileName
$cmd = $ISDeploymentWizard
$arg1 = "/Silent"
$arg1a= "/ModelType:Project"
$arg2 = "/SourcePath:""$ProjectFilePath"""
$arg3 = "/DestinationServer:""$SsisServer"""
$arg4 = "/DestinationPath:""$DestinationPath"""
$arg5 = "/ProjectPassword:""$ProjectFilePassword"""
Write-Host "$cmd" $arg1 $arg1a $arg2 $arg3 $arg4 $arg5
& "$cmd" $arg1 $arg1a $arg2 $arg3 $arg4 $arg5


Write-Host "Done"
#endregion 

【问题讨论】:

  • 你的执行行不是缺少$cmd 吗?您现在正尝试运行$arg1
  • 确实如此。但现在我有一个不同的错误:| (见问题)
  • 用直引号替换所有卷曲的“智能”引号
  • 这是由于stackoverflow的格式化:|
  • 你尝试过纯powershell解决方案吗? docs.microsoft.com/en-us/sql/integration-services/…

标签: sql-server powershell deployment ssis


【解决方案1】:

下面的变量不需要声明$arg1 $arg1a $arg2 $arg3 $arg4 $arg5,只需运行下面的命令(为什么要声明变量并将它们的值存储在另一个变量中??)

& $cmd /Silent /ModelType:Project /SourcePath:$ProjectFilePath /DestinationServer:$SsisServer /DestinationPath:$DestinationPath /ProjectPassword:$ProjectFilePassword

【讨论】:

  • 做到了!现在部署运行。
【解决方案2】:

您在Write-Host 下方的行中缺少可执行文件。

改变

& $arg1 $arg2 $arg3 $arg4 $arg5 

& $cmd $arg1 $arg2 $arg3 $arg4 $arg5 

【讨论】:

  • 我做到了。我还注意到手动运行 ISDeploymentWizard 时提供的字符串有一个额外的参数。我也补充了。但是当我现在运行它时,我得到了一个不同的错误(更新的问题)
【解决方案3】:

如果您在powershell中启动控制台应用程序有问题(通常是因为多个参数),您可以通过cmd(在powershell中)执行它

cmd /c "$cmd $arg1 $arg2 $arg3 $arg4 $arg5"

还有另一个选项使用 Process 类,所以你不必使用 cmd:

$ProcessInfo = New-Object System.Diagnostics.ProcessStartInfo 
$ProcessInfo.FileName = "D:\Deploy\ISDeploymentWizard.exe"
$ProcessInfo.Arguments = "$arg1 $arg1a $arg2 $arg3 $arg4 $arg5"
$ProcessInfo.RedirectStandardError = $true 
$ProcessInfo.RedirectStandardOutput = $true 
$ProcessInfo.UseShellExecute = $false 
$Process = New-Object System.Diagnostics.Process 
$Process.StartInfo = $ProcessInfo 

$Process.Start() | Out-Null 
$output = $Process.StandardOutput.ReadToEnd() 
$errors = $Process.StandardError.ReadToEnd()
$Process.WaitForExit() 
Write-Host $output 
Write-Error $errors 

您可以查看这里以获取更多详细信息: PowerShell, stream Process output and errors while running external process

【讨论】:

  • 不幸的是,它仍然在 Destinationpath 上失败。我尝试了一个没有空格的目标路径,但它给了我同样的错误。所以它似乎不是导致错误的destinationpath的内容。
  • 奇怪。你可以从控制台复制一个工作命令(没有字符串构建)。像 cmd /c 'working command here' 也尝试使用单引号,有时很重要
  • 也检查这个链接,它使用稍微不同的方法(对于 PS)stackoverflow.com/questions/21555086/…
  • 尝试从目标文件夹中删除空格(有人提到这可能是一个问题)。我认为您还可以将工作 cmd 命令保存为 bat 文件,然后从 powershell 调用它(通过输入该 bat 的完整路径)
  • 刚刚意识到还有另一种方法,更新了我的答案
【解决方案4】:

很确定$DestinationPath 必须是非相对路径。将其更改为包括驱动器在内的完整路径,我认为这将解决您的问题。

【讨论】:

  • DestinationPath 是 SSIS 目录中的目标路径。我认为没有涉及到驱动器?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-27
  • 1970-01-01
  • 1970-01-01
  • 2012-01-18
  • 1970-01-01
  • 1970-01-01
  • 2014-12-25
相关资源
最近更新 更多