共用方式為


使用 PowerShell 部署 SSIS 專案

適用於:SQL ServerAzure 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 專案。

注意

以下腳本需要 Microsoft.Data.SqlClient 組合語言。 從 NuGet 套件 安裝,並確保 DLL 對 PowerShell 可存取。 你可以在執行腳本之前載入 Add-Type -Path "path\to\Microsoft.Data.SqlClient.dll"

下列範例會使用 Windows 驗證來部署至內部部署的 SQL Server。 若要使用 SQL Server 驗證,請使用 Integrated Security=SSPI; 取代 User ID=<user name>;Password=<password>; 引數。 如果要連線至 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 Microsoft.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."