使用 PowerShell 运行 SSIS 包

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

本快速入门演示如何使用 PowerShell 脚本连接到数据库服务器并运行 SSIS 包。

先决条件

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

受支持的平台

可使用此快速入门中的信息在以下平台上运行 SSIS 包:

无法使用此快速入门中的信息在 Linux 上运行 SSIS 包。 有关在 Linux 上运行包的详细信息,请参阅使用 SSIS 在 Linux 上提取、转换和加载数据

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

要在 Azure SQL 数据库上运行包,请获取连接到 SSIS 目录数据库 (SSISDB) 所需的连接信息。 在接下来的步骤中需要完全限定的服务器名称和登录信息。

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

SSIS PowerShell 提供程序

可以使用 SSIS PowerShell 提供程序连接到 SSIS 目录并在其中执行包。

下面是如何使用 SSIS PowerShell 提供程序在包目录中执行 SSIS 包的基本示例。

(Get-ChildItem SQLSERVER:\SSIS\localhost\Default\Catalogs\SSISDB\Folders\Project1Folder\Projects\'Integration Services Project1'\Packages\ |
WHERE { $_.Name -eq 'Package.dtsx' }).Execute("false", $null)

PowerShell 脚本

为以下脚本顶部的变量提供相应的值,然后运行脚本以运行 SSIS 包。

注意

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

# Variables
$SSISNamespace = "Microsoft.SqlServer.Management.IntegrationServices"
$TargetServerName = "localhost"
$TargetFolderName = "Project1Folder"
$ProjectName = "Integration Services Project1"
$PackageName = "Package.dtsx"

# Load the IntegrationServices assembly
$loadStatus = [System.Reflection.Assembly]::Load("Microsoft.SQLServer.Management.IntegrationServices, "+
    "Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL")

# Create a connection to the server
$sqlConnectionString = `
    "Data Source=" + $TargetServerName + ";Initial Catalog=master;Integrated Security=SSPI;"
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString

# Create the Integration Services object
$integrationServices = New-Object $SSISNamespace".IntegrationServices" $sqlConnection

# Get the Integration Services catalog
$catalog = $integrationServices.Catalogs["SSISDB"]

# Get the folder
$folder = $catalog.Folders[$TargetFolderName]

# Get the project
$project = $folder.Projects[$ProjectName]

# Get the package
$package = $project.Packages[$PackageName]

Write-Host "Running " $PackageName "..."

$result = $package.Execute("false", $null)

Write-Host "Done."

后续步骤