Last active
August 29, 2015 14:04
-
-
Save billinkc/64d2168964a6f15d45bc to your computer and use it in GitHub Desktop.
PowerShell ManagedObjectModel deploy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Management.IntegrationServices") | Out-Null | |
#this allows the debug messages to be shown | |
$DebugPreference = "Continue" | |
# Retrieves a 2012 Integration Services CatalogFolder object | |
# Creates one if not found | |
Function Get-CatalogFolder | |
{ | |
param | |
( | |
[string] $folderName | |
, [string] $folderDescription | |
, [string] $serverName = "localhost\dev2012" | |
) | |
$connectionString = [String]::Format("Data Source={0};Initial Catalog=msdb;Integrated Security=SSPI;", $serverName) | |
$connection = New-Object System.Data.SqlClient.SqlConnection($connectionString) | |
$integrationServices = New-Object Microsoft.SqlServer.Management.IntegrationServices.IntegrationServices($connection) | |
# The one, the only SSISDB catalog | |
$catalog = $integrationServices.Catalogs["SSISDB"] | |
$catalogFolder = $catalog.Folders[$folderName] | |
if (-not $catalogFolder) | |
{ | |
Write-Debug([System.string]::Format("Creating folder {0}", $folderName)) | |
$catalogFolder = New-Object Microsoft.SqlServer.Management.IntegrationServices.CatalogFolder($catalog, $folderName, $folderDescription) | |
$catalogFolder.Create() | |
} | |
else | |
{ | |
$catalogFolder.Description = "Modified for SO2" | |
$catalogFolder.Alter() | |
Write-Debug([System.string]::Format("Existing folder {0}", $folderName)) | |
} | |
return $catalogFolder | |
} | |
# Deploy an ispac file into the SSISDB catalog | |
Function Deploy-Project | |
{ | |
param | |
( | |
[string] $projectPath | |
, [string] $projectName | |
, $catalogFolder | |
) | |
# test to ensure file exists | |
if (-not $projectPath -or -not (Test-Path $projectPath)) | |
{ | |
Write-Debug("File not found $projectPath") | |
return | |
} | |
Write-Debug($catalogFolder.Name) | |
Write-Debug("Deploying $projectPath") | |
# read the data into a byte array | |
[byte[]] $projectStream = [System.IO.File]::ReadAllBytes($projectPath) | |
# $ProjectName MUST match the value in the .ispac file | |
# else you will see | |
# Failed to deploy the project. Fix the problems and try again later.:The specified project name, test, does not match the project name in the deployment file. | |
$projectName = "HR Import Raw" | |
$projectName = "SSIS2012" | |
$project = $catalogFolder.DeployProject($projectName, $projectStream) | |
} | |
$isPac = "C:\tmp\ispac\HR Import Raw.ispac" | |
$isPac = "C:\Dropbox\Sandbox\SSIS2012\SSIS2012\bin\DEV2012\SSIS2012.ispac" | |
$folderName = "ProdSupport HR export" | |
$folderName = "SSIS2012" | |
$folderDescription = "Prod deployment check" | |
$serverName = "localhost\dev2012" | |
$catalogFolder = Get-CatalogFolder $folderName $folderDescription $serverName | |
Deploy-Project $isPac $projectName $catalogFolder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment