我有一个PS脚本,该脚本应该将项目部署到我的SSIS服务器。 当我在控制台中运行生成的命令时,它运行良好,但是从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
答案 0 :(得分:3)
无需声明以下变量$arg1 $arg1a $arg2 $arg3 $arg4 $arg5
,只需运行以下命令(为什么要声明变量并将其值存储在另一个变量中??):
& $cmd /Silent /ModelType:Project /SourcePath:$ProjectFilePath /DestinationServer:$SsisServer /DestinationPath:$DestinationPath /ProjectPassword:$ProjectFilePassword
答案 1 :(得分:2)
您在Write-Host
下面的行中缺少可执行文件。
更改
& $arg1 $arg2 $arg3 $arg4 $arg5
到
& $cmd $arg1 $arg2 $arg3 $arg4 $arg5
答案 2 :(得分:1)
如果您在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
答案 3 :(得分:-1)
请确保$DestinationPath
必须是非相对路径。将其更改为包括驱动器在内的完整路径,我认为这将解决您的问题。