我必须实现一个解决方案,我必须将SSIS项目(xy. ispac)从一台机器部署到另一台机器。到目前为止,我已经设法从Internet上复制-剪切-粘贴了以下内容:
# Variables
$ServerName = "target"
$SSISCatalog = "SSISDB" # sort of constant
$CatalogPwd = "catalog_password"
$ProjectFilePath = "D:\Projects_to_depoly\Project_1.ispac"
$ProjectName = "Project_name"
$FolderName = "Data_collector"
# Load the IntegrationServices Assembly
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Management.IntegrationServices")
# Store the IntegrationServices Assembly namespace to avoid typing it every time
$ISNamespace = "Microsoft.SqlServer.Management.IntegrationServices"
Write-Host "Connecting to server ..."
# Create a connection to the server
$sqlConnectionString = "Data Source=$ServerName;Initial Catalog=master;Integrated Security=SSPI;"
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString
$integrationServices = New-Object "$ISNamespace.IntegrationServices" $sqlConnection
$catalog = $integrationServices.Catalogs[$SSISCatalog]
# Create the Integration Services object if it does not exist
if (!$catalog) {
# Provision a new SSIS Catalog
Write-Host "Creating SSIS Catalog ..."
$catalog = New-Object "$ISNamespace.Catalog" ($integrationServices, $SSISCatalog, $CatalogPwd)
$catalog.Create()
}
$folder = $catalog.Folders[$FolderName]
if (!$folder)
{
#Create a folder in SSISDB
Write-Host "Creating Folder ..."
$folder = New-Object "$ISNamespace.CatalogFolder" ($catalog, $FolderName, $FolderName)
$folder.Create()
}
# Read the project file, and deploy it to the folder
Write-Host "Deploying Project ..."
[byte[]] $projectFile = [System.IO.File]::ReadAllBytes($ProjectFilePath)
$folder.DeployProject($ProjectName, $projectFile)
这似乎在开发机器-测试服务器对上运行得非常好。然而,实际环境会有所不同,执行部署工作的机器(部署服务器,或从现在开始的DS)和要部署项目的SQL服务器(简称DB)位于不同的域中,由于SSIS需要Windows身份验证,我需要在DS本地运行上述代码,但使用DB上用户的凭据。
这就是我失败的地方。唯一有效的方法是使用runas /netonly /user启动Powershell命令行界面:输入密码,然后将未更改的脚本粘贴到其中。唉,这不是一个选项,因为没有办法将密码传递给runas(至少一次使用 /savecred),用户交互也是不可能的(整个过程必须自动化)。
我尝试了以下方法:
$sqlConnection=New-ObjectSystem.Data。SqlClient. SqlConnection$sqlConnectionString
将使用DB无法识别的DS的凭据,并且New-Object没有我可以传递给的-Credential arg关于如何克服这个问题的任何提示?
一个解决方案可能是使用sql用户(具有正确的访问权限)而不是使用AD。类似的东西应该可以工作。(也检查正确连接字符串的答案)