forked from magnusneck/SsisPowershellTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-SsisContent.ps1
539 lines (425 loc) · 20.7 KB
/
Get-SsisContent.ps1
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
<#
.Synopsis
Extract Task and component information from SSIS (dtsx) files.
.DESCRIPTION
The purpose of this cmdlet is to extract information regarding tasks and components from
SSIS files (dtsx). The information can be used for statistical analysis or when you need to
search for some components in a set of SSIS files.
.EXAMPLE
Get-ChildItem -Path C:\work\release\etl *.dtsx -Recurse | get-SsisContent | Sort-Object Category, ComponentType | Group-Object Category, ComponentType | Select-Object Name, Count | Format-Table -AutoSize
Name Count
---- -----
Data Flow Component, Aggregate 6
Data Flow Component, Checksum Transformation 94
Data Flow Component, Conditional Split 308
Data Flow Component, Copy Column 4
Data Flow Component, Data Conversion 31
Data Flow Component, Derived Column 1430
Data Flow Component, Executes a custom script. 15
Data Flow Component, Extracts data from a raw file. 15
Data Flow Component, Flat File Destination 6
Data Flow Component, Flat File Source 185
Data Flow Component, http://ssismhash.codeplex.com/ 5
Data Flow Component, Kimball Method Slowly Changing Dimension 22
Data Flow Component, Lookup 614
Data Flow Component, Merge 1
Data Flow Component, Merge Join 6
Data Flow Component, Multicast 20
Data Flow Component, OLE DB Command 97
Data Flow Component, OLE DB Destination 573
Data Flow Component, OLE DB Source 356
Data Flow Component, Recordset Destination 22
Data Flow Component, Row Count 603
Data Flow Component, Slowly Changing Dimension 11
Data Flow Component, Sort 24
Data Flow Component, Union All 218
Task, Data Flow Task 436
Task, Execute Package Task 937
Task, Execute Process Task 3
Task, Execute SQL Task 1247
(What kind of components does the SSIS files contain and how many in total)
.EXAMPLE
Get-ChildItem -Path C:\work\release\etl *.dtsx -Recurse | get-SsisContent | Where-Object { $_.ComponentType -eq 'Kimball Method Slowly Changing Dimension' } | Select-Object FileName, TaskName | Format-List *
FileName : {C:\work\release\etl\File1.dtsx}
TaskName : DFT - Load Person
FileName : {C:\work\release\etl\File1.dtsx}
TaskName : DFT - Load Branch
FileName : {C:\work\release\etl\File2.dtsx}
TaskName : DFT - Load counterparty
(Which SSIS files uses the "Kimball Method Slowly Changing Dimension" component?)
.OUTPUTS
SsisTools.SsisContent
- FileName = Name of the file
- Category = Task, Data flow component, Variable, Package Configuration or Connection
- TaskName = Name of the task in the Control flow
- ComponentName = Name of the component in the Data Flow Task. Taskname for Control flow tasks
- ComponentType = Type of component, e.g "OLE DB Source"
#>
function Get-SsisContent
{
[CmdletBinding(SupportsShouldProcess=$false,
PositionalBinding=$false)]
[OutputType('SsisTools.SsisContent')]
Param
(
<#
File names to search. Only *.dtsx files are queried, others are ignored.
This parameter can be Pipelined to the script, e.g by Get-ChildItem.
#>
[Parameter(Mandatory,
ValueFromPipeline,
ValueFromPipelineByPropertyName,
ValueFromRemainingArguments=$false,
Position=0)]
[ValidateScript({Test-path $_})]
[Alias("FileName", "FullName")]
[String[]]$Path,
<#
{ "All", "Task", "Package configuration", "Connection", "Variable", "Data Flow Component" }
What kind of categories should be queried?
#>
[ValidateSet("All", "Task", "Package configuration", "Connection", "Variable", "Data Flow Component")]
[string[]]$Category = "All"
)
Begin
{
}
Process
{
# Private functions used in processing
function shouldProcess
{
Param(
[string[]]$categories,
[string]$category
)
($categories -contains $category -or $categories -contains "All")
}
function writeContentObject
{
Param(
[Parameter(Position=1)]
[string]$fileName,
[Parameter(Position=2)]
[string]$taskName,
[Parameter(Position=3)]
[string]$category,
[Parameter(Position=4)]
[string]$componentType,
[Parameter(Position=5)]
[string]$componentName
)
$prop = @{
'FileName'=$fileName
'Category'=$category
'ComponentType'=$componentType
'TaskName'=$taskName
'ComponentName'=$componentName
}
$obj=New-Object -TypeName PSObject -Property $prop
$obj.PSObject.TypeNames.Insert(0,’SsisTools.SsisContent’)
Write-Output $obj
}
function ExtractTasks2008
{
Param(
[Parameter(Position=1)]
[string]$fileName,
[Parameter(Mandatory, Position=2)]
[xml]$xml,
[Parameter(Mandatory, Position=3)]
[Xml.XmlNamespaceManager]$ns
)
$xml.SelectNodes("/DTS:Executable//DTS:Executable/DTS:Property[@DTS:Name='ObjectName']", $ns) | ForEach-Object {
$taskName = $_.InnerText
$taskContact = $_.SelectSingleNode("../DTS:Property[@DTS:Name='TaskContact']", $ns).InnerText
$taskDescription = $_.SelectSingleNode("../DTS:Property[@DTS:Name='Description']", $ns).InnerText
$executableType = $_.SelectSingleNode("../@DTS:ExecutableType", $ns).Value.ToString()
[System.Xml.xmlElement]$taskExecutePackageTaskObjectData = $_.SelectSingleNode("../DTS:ObjectData/ExecutePackageTask", $ns)
if ($taskExecutePackageTaskObjectData -ne $null) {
$taskType = "Execute Package Task"
}
elseif ($executableType -eq "STOCK:SEQUENCE") {
$taskType = "Sequence Container"
}
elseif ($executableType -eq "STOCK:FOREACHLOOP") {
$taskType = "For each loop"
}
# Some task have bad contact info - use Description for these
elseif ($taskDescription -in ("Data Flow Task", "Script Task", "Foreach Loop Container") -or $taskContact -like "Microsoft*" ) {
$taskType = $taskDescription
}
else {
$taskType = ($taskContact -split ";")[0]
}
writeContentObject $fileName $taskName 'Task' $taskType $taskName
}
}
function ExtractTasks2014
{
Param(
[Parameter(Position=1)]
[string]$fileName,
[Parameter(Mandatory, Position=2)]
[xml]$xml,
[Parameter(Mandatory, Position=3)]
[Xml.XmlNamespaceManager]$ns
)
$xml.SelectNodes("/DTS:Executable//DTS:Executable", $ns) | ForEach-Object {
$taskName = $_.GetAttribute("DTS:ObjectName")
$taskContact = $_.GetAttribute("DTS:TaskContact")
$taskDescription = $_.GetAttribute("DTS:Description")
$executableType = $_.GetAttribute("DTS:ExecutableType")
[System.Xml.xmlElement]$taskExecutePackageTaskObjectData = $_.SelectSingleNode("DTS:ObjectData/ExecutePackageTask", $ns)
if ($taskExecutePackageTaskObjectData -ne $null) {
$taskType = "Execute Package Task"
}
elseif ($executableType -eq "STOCK:SEQUENCE") {
$taskType = "Sequence Container"
}
elseif ($executableType -eq "STOCK:FOREACHLOOP") {
$taskType = "For each loop"
}
elseif ($executableType -eq "Microsoft.ScriptTask") {
$taskType = "Script Task"
}
# Some task have bad contact info - use Description for these
elseif ($taskDescription -in ("Data Flow Task", "Script Task", "Foreach Loop Container") -or $taskContact -like "Microsoft*" ) {
$taskType = $taskDescription
}
else {
$taskType = ($taskContact -split ";")[0]
}
writeContentObject $fileName $taskName 'Task' $taskType $taskName
}
}
function ExtractVariables2008
{
Param(
[Parameter(Position=1)]
[string]$fileName,
[Parameter(Mandatory, Position=2)]
[xml]$xml,
[Parameter(Mandatory, Position=3)]
[Xml.XmlNamespaceManager]$ns
)
$xml.SelectNodes("//DTS:Variable/DTS:Property[@DTS:Name='Namespace' and text() != 'System']/..", $ns) | ForEach-Object {
$variableName = $_.SelectSingleNode("DTS:Property[@DTS:Name='ObjectName']", $ns).InnerText
$namespace = $_.SelectSingleNode("DTS:Property[@DTS:Name='Namespace']", $ns).InnerText
writeContentObject $fileName $variableName 'Variable' "${namespace}Variable" $variableName
}
}
function ExtractVariables2014
{
Param(
[Parameter(Position=1)]
[string]$fileName,
[Parameter(Mandatory, Position=2)]
[xml]$xml,
[Parameter(Mandatory, Position=3)]
[Xml.XmlNamespaceManager]$ns
)
$xml.SelectNodes("//DTS:Variables/DTS:Variable[@DTS:Namespace != 'System']", $ns) | ForEach-Object {
$variableName = $_.GetAttribute("DTS:ObjectName")
$namespace = $_.GetAttribute("DTS:Namespace")
writeContentObject $fileName $variableName 'Variable' "${namespace}Variable" $variableName
}
}
function ExtractConfigurations2008
{
Param(
[Parameter(Position=1)]
[string]$fileName,
[Parameter(Mandatory, Position=2)]
[xml]$xml,
[Parameter(Mandatory, Position=3)]
[Xml.XmlNamespaceManager]$ns
)
$xml.SelectNodes("//DTS:Configuration/DTS:Property[@DTS:Name='ConfigurationString']/..", $ns) | ForEach-Object {
$configurationString = $_.SelectSingleNode("DTS:Property[@DTS:Name='ConfigurationString']", $ns).InnerText
$configurationName = $_.SelectSingleNode("DTS:Property[@DTS:Name='ObjectName']", $ns).InnerText
$configurationTypeInt = $_.SelectSingleNode("DTS:Property[@DTS:Name='ConfigurationType']", $ns).InnerText
$configurationType = switch ($configurationTypeInt) {
0 {"Parent package variable"}
2 {"Environment variable"}
5 {"Indirect XML configuration file"}
default {"Unknown $configurationTypeInt"}
}
writeContentObject $fileName $configurationName 'Package configuration' $configurationType $configurationString
}
}
function ExtractConfigurations2014
{
Param(
[Parameter(Position=1)]
[string]$fileName,
[Parameter(Mandatory, Position=2)]
[xml]$xml,
[Parameter(Mandatory, Position=3)]
[Xml.XmlNamespaceManager]$ns
)
$xml.SelectNodes("//DTS:Configuration", $ns) | ForEach-Object {
$configurationString = $_.GetAttribute("DTS:ConfigurationString")
$configurationName = $_.GetAttribute("DTS:ObjectName")
$configurationTypeInt = $_.GetAttribute("DTS:ConfigurationType")
if ($configurationTypeInt -eq "") {
# The ConfigurationType 0 seems to be removed in SSIS 2014.
$configurationTypeInt = 0
}
$configurationType = switch ($configurationTypeInt) {
0 {"Parent package variable"}
2 {"Environment variable"}
5 {"Indirect XML configuration file"}
default {"Unknown $configurationTypeInt"}
}
writeContentObject $fileName $configurationName 'Package configuration' $configurationType $configurationString
}
}
function ExtractConnections2008
{
Param(
[Parameter(Position=1)]
[string]$fileName,
[Parameter(Mandatory, Position=2)]
[xml]$xml,
[Parameter(Mandatory, Position=3)]
[Xml.XmlNamespaceManager]$ns
)
$xml.SelectNodes("/DTS:Executable/DTS:ConnectionManager", $ns) | ForEach-Object {
$connectionName = $_.SelectSingleNode("DTS:Property[@DTS:Name='ObjectName']", $ns).InnerText
# FILE, FLATFILE, FTP, OLE DB
$creationName = $_.SelectSingleNode("DTS:Property[@DTS:Name='CreationName']", $ns).InnerText
writeContentObject $fileName $connectionName 'Connection' $creationName $connectionName
}
}
function ExtractConnections2014
{
Param(
[Parameter(Position=1)]
[string]$fileName,
[Parameter(Mandatory, Position=2)]
[xml]$xml,
[Parameter(Mandatory, Position=3)]
[Xml.XmlNamespaceManager]$ns
)
$xml.SelectNodes("/DTS:Executable/DTS:ConnectionManagers/DTS:ConnectionManager", $ns) | ForEach-Object {
$connectionName = $_.GetAttribute("DTS:ObjectName")
# FILE, FLATFILE, FTP, OLE DB
$creationName = $_.GetAttribute("DTS:CreationName")
writeContentObject $fileName $connectionName 'Connection' $creationName $connectionName
}
}
function ExtractDataFlowComponents2008
{
Param(
[Parameter(Position=1)]
[string]$fileName,
[Parameter(Mandatory, Position=2)]
[xml]$xml,
[Parameter(Mandatory, Position=3)]
[Xml.XmlNamespaceManager]$ns
)
$xml.SelectNodes("//components/component", $ns) | ForEach-Object {
$componentName = $_.SelectSingleNode("@name", $ns).Value.ToString()
$componentDescription = $_.SelectSingleNode("@description", $ns).Value.ToString()
$taskName = $_.SelectSingleNode("../../../../DTS:Property[@DTS:Name='ObjectName']", $ns).InnerText
$contactInfo = $_.SelectSingleNode("@contactInfo", $ns).Value.ToString()
$componentType = ($contactInfo -split ";")[0]
if ($componentType -eq "") {
$componentType = $ComponentDescription
}
# Still no component type? Use Component name (Kimball SCD)
if ($componentType -eq "") {
$componentType = $componentName
}
writeContentObject $fileName $taskName 'Data Flow Component' $componentType $componentName
}
}
function ExtractDataFlowComponents2014
{
Param(
[Parameter(Position=1)]
[string]$fileName,
[Parameter(Mandatory, Position=2)]
[xml]$xml,
[Parameter(Mandatory, Position=3)]
[Xml.XmlNamespaceManager]$ns
)
$xml.SelectNodes("//components/component", $ns) | ForEach-Object {
$componentName = $_.SelectSingleNode("@name", $ns).Value.ToString()
$componentDescription = $_.GetAttribute("description")
$dftTask = $_.SelectSingleNode("../../../..")
$taskName = $dftTask.GetAttribute("DTS:ObjectName")
$contactInfo = $_.GetAttribute("contactInfo")
$componentType = ($contactInfo -split ";")[0]
if ($componentType -eq "") {
$componentType = $ComponentDescription
}
# Still no component type? Use Component name (Kimball SCD)
if ($componentType -eq "") {
$componentType = $componentName
}
writeContentObject $fileName $taskName 'Data Flow Component' $componentType $componentName
}
}
if ($Path -like "*.dtsx") {
Write-Verbose "File: $Path"
[xml]$xml = Get-Content -Path $Path
$ns = new-object Xml.XmlNamespaceManager ($xml.NameTable)
$ns.AddNamespace("SQLTask", "www.microsoft.com/sqlserver/dts/tasks/sqltask")
$ns.AddNamespace("DTS", "www.microsoft.com/SqlServer/Dts")
$PackageFormatVersion = $xml.SelectSingleNode("/DTS:Executable/DTS:Property[@DTS:Name='PackageFormatVersion']", $ns).InnerText
if ($PackageFormatVersion -notin ("3", "8")) {
Write-Verbose "Warning: $Path has unsupported PackageFormatVersion: ${PackageFormatVersion}. Ignoring file"
}
else {
# Control flow tasks
if (shouldProcess $Category 'Task') {
switch ($PackageFormatVersion) {
"3" {ExtractTasks2008 $Path[0] $xml $ns}
"8" {ExtractTasks2014 $Path[0] $xml $ns}
default {}
}
}
# Variables
if (shouldProcess $Category 'Variable') {
switch ($PackageFormatVersion) {
"3" {ExtractVariables2008 $Path[0] $xml $ns}
"8" {ExtractVariables2014 $Path[0] $xml $ns}
default {}
}
}
# Configurations
if (shouldProcess $Category 'Package configuration') {
switch ($PackageFormatVersion) {
"3" {ExtractConfigurations2008 $Path[0] $xml $ns}
"8" {ExtractConfigurations2014 $Path[0] $xml $ns}
default {}
}
}
# Connections
if (shouldProcess $Category 'Connection') {
switch ($PackageFormatVersion) {
"3" {ExtractConnections2008 $Path[0] $xml $ns}
"8" {ExtractConnections2014 $Path[0] $xml $ns}
default {}
}
}
# Data flow components
if (shouldProcess $Category 'Data Flow Component') {
switch ($PackageFormatVersion) {
"3" {ExtractDataFlowComponents2008 $Path[0] $xml $ns}
"8" {ExtractDataFlowComponents2014 $Path[0] $xml $ns}
default {}
}
}
}
}
else {
Write-Verbose "File $Path is not a dtsx file"
}
}
End
{
}
}