sql-server - 命令在控制台中运行良好,但在 Powershell 使用时运行不佳

标签 sql-server powershell deployment ssis

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

TITLE: SQL Server Integration Services

The path format is invalid. Parameter name: DestinationPath (ISDeploymentWizard)

ADDITIONAL INFORMATION:

The path format is invalid. (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 

最佳答案

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

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

关于sql-server - 命令在控制台中运行良好,但在 Powershell 使用时运行不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53533984/

相关文章:

sql-server - SSIS WebService 任务插入 XML header

c# - 将 Android 应用程序连接到 SQL Server

powershell - 如何检查 PowerShell 开关参数是否不存在或错误

powershell - 在命令行中找不到 Cmdlet,但在 ISE 中可用

sql-server - SQL Server - 值得为大字符串键建立索引吗?

php - "Incorrect SQLSTATE given to is_truncated_warning."在 Debian Linux 中使用 PHP 和 SQLSRV

powershell - flutter 医生不适用于命令提示符或 PowerShell 窗口?

spring-boot - 在 tomcat 上部署 spring boot 应用程序,我应该替换我所有应用程序的 url

xcode - Swift Storyboards MAC OSX 10.9 部署

sql-server - 使用 PowerShell 在客户计算机上部署 SSRS 报告