gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 16:22:40 24 4
gpt4 key购买 nike

我有一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com