-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExport-SSISProjectSSISDB.ps1
More file actions
95 lines (67 loc) · 2.54 KB
/
Export-SSISProjectSSISDB.ps1
File metadata and controls
95 lines (67 loc) · 2.54 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function Export-SSISProjectSSISDB
{
param
(
[Parameter(position=0, mandatory=$true)][string]$Instance,
[Parameter(position=1, mandatory=$true)][string]$OutputDir
)
if(!(Test-Path $OutputDir))
{
Write-Output "Error - invalid path specified in OutputDir"
return
}
$testquery = "SELECT COUNT(*) AS 'Result' FROM sys.databases WHERE name = 'SSISDB'"
try
{
$result = (Invoke-Sqlcmd -ServerInstance $Instance -Query $testquery -ConnectionTimeout 5 -QueryTimeout 5 -ErrorAction Stop).Result
if($result -eq 0)
{
Write-Output "Error - no SSISDB present on instance or no permission to view it"
return
}
}
catch
{
Write-Output "Error - failure connecting to instance"
return
}
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Management.IntegrationServices") | Out-Null
$SSISnamespace = "Microsoft.SqlServer.Management.IntegrationServices"
$connstring = "Data source=$($Instance);Initial Catalog=master;Integrated Security=SSPI;"
$sqlconn = New-Object System.Data.SqlClient.SqlConnection $connstring
$SSIS = New-Object $SSISnamespace".IntegrationServices" $sqlconn
$catalog = $SSIS.Catalogs["SSISDB"]
foreach($folder in $catalog.Folders)
{
Set-Location -Path $outputdir
New-Item -ItemType Directory -Name $folder.Name | Out-Null
$folderpath = $outputdir + "\" + $folder.Name
Set-Location -path $folderpath
$projects = $folder.Projects
if($projects.Count -gt 0)
{
foreach($project in $projects)
{
$projectpath = $folderpath + "\" + $project.Name + ".ispac"
Write-Host "Exporting to $($projectpath) ...";
[System.IO.File]::WriteAllBytes($projectpath, $project.GetProjectBytes())
}
}
}
Set-Location -Path $outputdir
<#
.SYNOPSIS
Exports all SSIS projects from an SSISDB database to a specified output directory
.DESCRIPTION
Retrieves all SSIS projects in .ispac format from an SSISDB database to a specified output directory, creating SSISDB folder structure.
.PARAMETER Instance
Specifies the SQL instance name
.PARAMETER OutputDir
Specifies the full output directory for SSISDB Folders/Projects to be exported to.
.OUTPUTS
No direct outputs from fuction - writes .ispac files.
.EXAMPLE
PS> Export-SSISProjectSSISDB -Instance SQLSSIS2014 -OutputDir "D:\DBA\SSIS\Export"
Exports all SSIS projects from instance SQLSSIS2014 as .ispac files to SSISDB Folder-named subfolders created in D:\DBA\SSIS\Export
#>
}