命令在控制台中正常运行,但在Powershell使用时则没有

Hen*_*rov 7 sql-server deployment powershell ssis

我有一个PS脚本,应该将项目部署到我的SSIS服务器.当我在控制台中运行生成的命令时它运行正常,但是当从Powershell执行命令时它会因为(windows)错误而失败:

标题:SQL Server Integration Services

路径格式无效.参数名称: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"
Run Code Online (Sandbox Code Playgroud)

剧本(感谢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 
Run Code Online (Sandbox Code Playgroud)

Yah*_*ufi 4

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

& $cmd /Silent /ModelType:Project /SourcePath:$ProjectFilePath /DestinationServer:$SsisServer /DestinationPath:$DestinationPath /ProjectPassword:$ProjectFilePassword
Run Code Online (Sandbox Code Playgroud)

  • 这做到了!现在部署运行。 (2认同)