-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSSIS_DeployISPAC.ps1
More file actions
51 lines (41 loc) · 1.94 KB
/
SSIS_DeployISPAC.ps1
File metadata and controls
51 lines (41 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Script to deploy SSIS package (ISPAC)
# ISPAC is built using devenv.exe
# Use computer name to get IP then store in $server variable for connection string below
$server = $env:computername
$ips = [System.Net.Dns]::GetHostAddresses($server)[0].IPAddressToString;
$server = $ips
write-host "Server IP:" $server
# Load the IntegrationServices Assembly
$loadStatus = [Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Management.IntegrationServices,Culture=neutral")
# Create a connection to the server
$constr = "Data Source=$server;Initial Catalog=master;Integrated Security=SSPI;"
$con = New-Object System.Data.SqlClient.SqlConnection $constr
# Store the IntegrationServices Assembly namespace to avoid typing it every time
$ISNamespace = "Microsoft.SqlServer.Management.IntegrationServices"
Write-Host "Connecting to server ..."
# Create the Integration Services object
$ssis = New-Object $ISNamespace".IntegrationServices" $con
# Check if catalog exists
if ($ssis.Catalogs.Count -eq 0)
{
Write-Error "SSISDB doesn't exist"
throw "SSISDB doesn't exist"
}
# Set catalog to SSISDB
$cat = $ssis.Catalogs["SSISDB"]
# If $ProjectName folder in SSISDB doesn't exist, create it
$folderName = "$ProjectName"
if ($cat.Folders[$folderName] -eq $null)
{
Write-Host "Creating new folder" $folderName
$newfolder = New-Object $ISNamespace".CatalogFolder" ($cat, $folderName, "Description")
$newfolder.Create()
}
# Set folder to catalog folder ($ProjectName)
$folder = $cat.Folders[$folderName]
# Set dir of ISPAC file
$localToLocalETLFullPath = "$PSScriptRoot\bin\$ProjectName.$DatabaseName.ispac"
# Read the project file, and deploy it to the folder
Write-Host "Deploying SSIS project ..."
[byte[]] $projectFile = [System.IO.File]::ReadAllBytes($localToLocalETLFullPath)
$folder.DeployProject("$ProjectName.$DatabaseName.ETL", $projectFile)