使用 PowerShell 部署 SSIS 專案

適用於:SQL Server Azure Data Factory 中的 SSIS Integration Runtime

本快速入門示範如何使用 PowerShell 指令碼連線至資料庫伺服器,並將 SSIS 專案部署到 SSIS 目錄。

先決條件

Azure SQL Database 伺服器會接聽連接埠 1433。 如果您要嘗試透過公司防火牆連線至 Azure SQL Database 伺服器,則必須在公司防火牆中開啟此連接埠,讓您成功連線。

支援的平台

您可以使用本快速入門中的資訊,將 SSIS 套件部署到下列平台:

您無法使用本快速入門中的資訊,將 SSIS 套件部署到 Linux 上的 SQL Server。 如需在 Linux 上執行套件的詳細資訊,請參閱使用 SSIS 在 Linux 上擷取、轉換和載入資料

針對 Azure SQL Database,請取得連線資訊

若要將專案部署到 Azure SQL Database,請取得連線至 SSIS 目錄資料庫 (SSISDB) 所需的連線資訊。 在下列程序中,您需要完整伺服器名稱和登入資訊。

  1. 登入 Azure 入口網站
  2. 從左側功能表中選取 [SQL 資料庫],然後選取 [SQL 資料庫] 頁面上的 SSISDB 資料庫。
  3. 在您資料庫的 [概觀] 頁面上,檢閱完整伺服器名稱。 若要顯示 [按一下以複製] 選項,請將滑鼠指標暫留在伺服器名稱上。
  4. 如果您忘記 Azure SQL Database 伺服器登入資訊,請巡覽至 [SQL Database 伺服器] 頁面來檢視伺服器管理員名稱。 如有需要,您可以重設密碼。
  5. 按一下 [顯示資料庫連接字串]
  6. 檢閱完整 ADO.NET 連接字串。

支援的驗證方法

請參閱適用於部署的驗證方法

SSIS PowerShell 提供者

為下列指令碼上方的變數提供適當的值,然後執行指令碼部署 SSIS 專案。

注意

下列範例會使用 Windows 驗證來部署至內部部署的 SQL Server。 使用 New-PSDive Cmdlet,以 SQL Server 驗證建立連線。 如果要連線至 Azure SQL Database 伺服器,您無法使用 Windows 驗證。

# Variables
$TargetInstanceName = "localhost\default"
$TargetFolderName = "Project1Folder"
$ProjectFilePath = "C:\Projects\Integration Services Project1\Integration Services Project1\bin\Development\Integration Services Project1.ispac"
$ProjectName = "Integration Services Project1"

# Get the Integration Services catalog
$catalog = Get-Item SQLSERVER:\SSIS\$TargetInstanceName\Catalogs\SSISDB\

# Create the target folder
New-Object "Microsoft.SqlServer.Management.IntegrationServices.CatalogFolder" ($catalog, 
$TargetFolderName,"Folder description") -OutVariable folder
$folder.Create()

# Read the project file and deploy it
[byte[]] $projectFile = [System.IO.File]::ReadAllBytes($ProjectFilePath)
$folder.DeployProject($ProjectName, $projectFile)

# Verify packages were deployed.
dir "$($catalog.PSPath)\Folders\$TargetFolderName\Projects\$ProjectName\Packages" | 
SELECT Name, DisplayName, PackageId

PowerShell 指令碼

為下列指令碼上方的變數提供適當的值,然後執行指令碼部署 SSIS 專案。

注意

下列範例會使用 Windows 驗證來部署至內部部署的 SQL Server。 若要使用 SQL Server 驗證,請使用 User ID=<user name>;Password=<password>; 取代 Integrated Security=SSPI; 引數。 如果要連線至 Azure SQL Database 伺服器,您無法使用 Windows 驗證。

# Variables
$SSISNamespace = "Microsoft.SqlServer.Management.IntegrationServices"
$TargetServerName = "localhost"
$TargetFolderName = "Project1Folder"
$ProjectFilePath = "C:\Projects\Integration Services Project1\Integration Services Project1\bin\Development\Integration Services Project1.ispac"
$ProjectName = "Integration Services Project1"

# 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"]

# Create the target folder
$folder = New-Object $SSISNamespace".CatalogFolder" ($catalog, $TargetFolderName,
    "Folder description")
$folder.Create()

Write-Host "Deploying " $ProjectName " project ..."

# Read the project file and deploy it
[byte[]] $projectFile = [System.IO.File]::ReadAllBytes($ProjectFilePath)
$folder.DeployProject($ProjectName, $projectFile)

Write-Host "Done."

後續步驟