使用 PowerShell 部署 SSIS 项目

适用于:SQL Server Azure 数据工厂中的 SSIS Integration Runtime

本快速入门演示了如何使用 PowerShell 脚本连接到数据库服务器,并将 SSIS 项目部署到 SSIS 目录。

先决条件

Azure SQL 数据库服务器在端口 1433 上进行侦听。 如果尝试从企业防火墙内连接到 Azure SQL 数据库服务器,必须在企业防火墙中打开该端口,才能成功连接。

受支持的平台

可使用此快速入门中的信息将 SSIS 项目部署到以下平台:

不能使用本快速入门中的信息将 SSIS 包部署到 Linux 上的 SQL Server。 有关在 Linux 上运行包的详细信息,请参阅使用 SSIS 在 Linux 上提取、转换和加载数据。

对于 Azure SQL 数据库,请获取连接信息

要将项目部署到 Azure SQL 数据库,则获取所需的信息以连接到 SSIS 目录数据库 (SSISDB)。 在接下来的步骤中需要完全限定的服务器名称和登录信息。

  1. 登录 Azure 门户。
  2. 从左侧的菜单选择“SQL 数据库”,然后选择“SQL 数据库”页中的 SSISDB 数据库。
  3. 在数据库的“概述”页上,查看完全限定的服务器名称。 若想查看“单击以复制”选项,将鼠标悬停在服务器名称上 。
  4. 如果忘记了 Azure SQL 数据库服务器登录信息,导航到 SQL 数据库服务器页以查看服务器管理员名称。 如有必要,可重置密码。
  5. 选择“ 显示数据库连接字符串”。
  6. 查看完整的 ADO.NET 连接字符串。

支持的身份验证方法

请参阅用于部署的身份验证方法。

PowerShell 脚本

为以下脚本顶部的变量提供适当的值,然后运行脚本以部署 SSIS 项目。

注意

以下示例使用 Windows 身份验证部署到本地 SQL Server。 要使用 SQL Server 身份验证,请将 Integrated Security=SSPI; 参数替换为 User ID=<user name>;Password=<password>;。 如果连接到 Azure SQL 数据库服务器,则无法使用 Windows 身份验证。

# ===== Param =====
$TargetSqlVersion  = '2025'   # 2017 / 2019 / 2022 / 2025
$TargetServerName  = 'localhost'
$TargetFolderName  = 'Project1Folder'
$ProjectName       = 'Integration Services Project1'
$ProjectFilePath   = 'C:\Projects\Integration Services Project1\Integration Services Project1\bin\Development\Integration Services Project1.ispac'
# ========================

$SSISNamespace  = 'Microsoft.SqlServer.Management.IntegrationServices'
$isV2025OrLater = [int]$TargetSqlVersion -ge 2025

if ($isV2025OrLater) {
    # 2025+ : need Microsoft.Data.SqlClient (shipped with SqlServer module 22.x)
    $required = '22.4.5.1'
    if (-not (Get-Module -ListAvailable -Name SqlServer |
              Where-Object { $_.Version -eq [version]$required })) {
        Install-Module -Name SqlServer -RequiredVersion $required -Scope CurrentUser -AllowClobber -Force
    }
    Import-Module SqlServer -RequiredVersion $required
    $sqlClientType = 'Microsoft.Data.SqlClient.SqlConnection'
}
else {
    # 2017 / 2019 / 2022 : in-box System.Data.SqlClient
    $sqlClientType = 'System.Data.SqlClient.SqlConnection'
}

[Reflection.Assembly]::LoadWithPartialName($SSISNamespace) | Out-Null
[Reflection.Assembly]::LoadWithPartialName(($SSISNamespace + 'Enum')) | Out-Null

$sqlConnectionString = "Data Source=$TargetServerName;Initial Catalog=master;Integrated Security=SSPI;Encrypt=True;TrustServerCertificate=True; 
$sqlConnection       = New-Object $sqlClientType $sqlConnectionString

$integrationServices = New-Object ($SSISNamespace + '.IntegrationServices') $sqlConnection
$catalog             = $integrationServices.Catalogs['SSISDB']

$folder = New-Object ($SSISNamespace + '.CatalogFolder') ($catalog, $TargetFolderName, 'Folder description')
$folder.Create()

Write-Host "Deploying $ProjectName ..."
[byte[]]$projectFile = [System.IO.File]::ReadAllBytes($ProjectFilePath)
$folder.DeployProject($ProjectName, $projectFile)
Write-Host 'Done.'