internal/scripts/smoLibraryImport.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
$scriptBlock = {
    param (
        $ModuleRoot,

        $DllRoot,

        $DoCopy
    )

    function Copy-Assembly {
        [CmdletBinding()]
        param (
            [string]$ModuleRoot,
            [string]$DllRoot,
            [bool]$DoCopy,
            [string]$Name
        )

        if (-not $DoCopy) {
            return
        }
        if ("$ModuleRoot\bin\smo" -eq $DllRoot) {
            return
        }

        if (-not (Test-Path $DllRoot)) {
            $null = New-Item -Path $DllRoot -ItemType Directory -ErrorAction Ignore
        }

        Copy-Item -Path "$ModuleRoot\bin\smo\$Name.dll" -Destination $DllRoot
    }

    #region Names
    $names = @(
        'Microsoft.SqlServer.Smo',
        'Microsoft.SqlServer.Dmf',
        'Microsoft.SqlServer.SqlWmiManagement',
        'Microsoft.SqlServer.ConnectionInfo',
        'Microsoft.SqlServer.SmoExtended',
        'Microsoft.SqlServer.Management.RegisteredServers',
        'Microsoft.SqlServer.Management.Sdk.Sfc',
        'Microsoft.SqlServer.SqlEnum',
        'Microsoft.SqlServer.RegSvrEnum',
        'Microsoft.SqlServer.WmiEnum',
        'Microsoft.SqlServer.ServiceBrokerEnum',
        'Microsoft.SqlServer.Management.Collector',
        'Microsoft.SqlServer.Management.CollectorEnum',
        'Microsoft.SqlServer.Management.Utility',
        'Microsoft.SqlServer.Management.UtilityEnum',
        'Microsoft.SqlServer.Management.HadrDMF',
        'Microsoft.SqlServer.VulnerabilityAssessment.Model',

        'Microsoft.SqlServer.BatchParser',
        'Microsoft.SqlServer.BatchParserClient',
        'Microsoft.SqlServer.BulkInsertTaskConnections',
        'Microsoft.SqlServer.DTSRuntimeWrap',
        'Microsoft.SqlServer.DtsServer.Interop',
        'Microsoft.SqlServer.DTSUtilities',
        'Microsoft.SqlServer.ForEachFileEnumeratorWrap',
        'Microsoft.SqlServer.ManagedDTS',
        'Microsoft.SqlServer.IntegrationServices.ODataConnectionManager',
        'Microsoft.SqlServer.IntegrationServices.ODataSrc',
        'Microsoft.SqlServer.PipelineHost',
        'Microsoft.SqlServer.PackageFormatUpdate',
        'Microsoft.SqlServer.Replication',
        'Microsoft.SqlServer.SqlCEDest',
        'Microsoft.SqlServer.SQLTask',
        'Microsoft.SqlServer.TxScript',
        'Microsoft.SqlServer.XE.Core',
        'Microsoft.SqlServer.XEvent.Configuration',
        'Microsoft.SqlServer.XEvent',
        'Microsoft.SqlServer.XEvent.Linq',
        'Microsoft.SqlServer.XmlSrc',
        'Microsoft.SqlServer.Rmo',
        'Microsoft.SqlServer.DTSPipelineWrap',
        'Microsoft.SqlServer.ScriptTask',

        'Accessibility',
        'EnvDTE',
        'Microsoft.AnalysisServices.AppLocal.Core',
        'Microsoft.AnalysisServices.AppLocal',
        'Microsoft.Azure.KeyVault.Core',
        'Microsoft.Data.Edm',
        'Microsoft.Data.OData',
        'Microsoft.Practices.TransientFaultHandling.Core',
        'Microsoft.DataTransfer.Common.Utils',
        'Microsoft.SqlServer.ASTasks',
        'Microsoft.SqlServer.ConnectionInfoExtended',
        'Microsoft.SqlServer.DataProfiler',
        'Microsoft.SqlServer.DataProfilingTask',
        'Microsoft.SqlServer.Diagnostics.STrace',
        'Microsoft.SqlServer.Dmf.Common',

        'Microsoft.SqlServer.DMQueryTask',
        'Microsoft.SqlServer.DTEnum',
        'Microsoft.SqlServer.Dts.Design',
        'Microsoft.SqlServer.Dts.DtsClient',
        'Microsoft.SqlServer.DtsMsg',
        'Microsoft.SqlServer.Edition',
        'Microsoft.SqlServer.ExecProcTask',
        'Microsoft.SqlServer.ExpressionTask',
        'Microsoft.SqlServer.FileSystemTask',
        'Microsoft.SqlServer.ForEachADOEnumerator',
        'Microsoft.SqlServer.ForEachFromVarEnumerator',
        'Microsoft.SqlServer.ForEachNodeListEnumerator',
        'Microsoft.SqlServer.ForEachSMOEnumerator',
        'Microsoft.SqlServer.FtpTask',
        'Microsoft.SqlServer.GridControl',
        'Microsoft.SqlServer.Instapi',
        'Microsoft.SqlServer.IntegrationServices.ClusterManagement',
        'Microsoft.SqlServer.IntegrationServices.Common.ObjectModel',
        'Microsoft.SqlServer.IntegrationServices.ISServerDBUpgrade',
        'Microsoft.SqlServer.IntegrationServices.Server.Common',
        'Microsoft.SqlServer.IntegrationServices.Server',
        'Microsoft.SqlServer.IntegrationServices.Server.IPC',
        'Microsoft.SqlServer.IntegrationServices.server.shared',
        'Microsoft.SqlServer.IntegrationServices.TaskScheduler',
        'Microsoft.SqlServer.ManagedConnections',
        'Microsoft.SqlServer.Management.CollectorTasks',
        'Microsoft.SqlServer.Management.HelpViewer',
        'Microsoft.SqlServer.Management.IntegrationServices',
        'Microsoft.SqlServer.Management.IntegrationServicesEnum',
        'Microsoft.SqlServer.Management.Sdk.Scripting',
        'Microsoft.SqlServer.Management.Sdk.SqlStudio',
        'Microsoft.SqlServer.Management.SmartAdminPolicies',
        'Microsoft.SqlServer.Management.SqlParser',
        'Microsoft.SqlServer.Management.SystemMetadataProvider',
        'Microsoft.SqlServer.Management.XEvent',
        'Microsoft.SqlServer.Management.XEventDbScoped',
        'Microsoft.SqlServer.Management.XEventDbScopedEnum',
        'Microsoft.SqlServer.Management.XEventEnum',
        'Microsoft.SqlServer.MSMQTask',
        'Microsoft.SqlServer.PipelineXML',
        'Microsoft.SqlServer.PolicyEnum',
        'Microsoft.SqlServer.Replication.BusinessLogicSupport',
        'Microsoft.SqlServer.SendMailTask',
        'Microsoft.SqlServer.SqlClrProvider',
        'Microsoft.SqlServer.SQLTaskConnectionsWrap',
        'Microsoft.SqlServer.SqlTDiagm',
        'Microsoft.SqlServer.SString',
        'Microsoft.SqlServer.TransferDatabasesTask',
        'Microsoft.SqlServer.TransferErrorMessagesTask',
        'Microsoft.SqlServer.TransferJobsTask',
        'Microsoft.SqlServer.TransferLoginsTask',
        'Microsoft.SqlServer.TransferObjectsTask',
        'Microsoft.SqlServer.TransferSqlServerObjectsTask',
        'Microsoft.SqlServer.TransferStoredProceduresTask',
        'Microsoft.SqlServer.Types',
        'Microsoft.SqlServer.Types.resources',
        'Microsoft.SqlServer.VSTAScriptingLib',
        'Microsoft.SqlServer.WebServiceTask',
        'Microsoft.SqlServer.WMIDRTask',
        'Microsoft.SqlServer.WMIEWTask',
        'Microsoft.SqlServer.XMLTask',

        'Microsoft.SqlServer.Dmf.Adapters',
        'Microsoft.SqlServer.DmfSqlClrWrapper'
    )
    #endregion Names

    foreach ($name in $names) {
        Copy-Assembly -ModuleRoot $ModuleRoot -DllRoot $DllRoot -DoCopy $DoCopy -Name $name
    }
    foreach ($name in $names) {
        Add-Type -Path "$DllRoot\$name.dll"
    }

    <#
Likely don't need yet
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.WizardFramework.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.WizardFrameworkLite.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.IntegrationServices.WorkerAgent.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.IntegrationServices.SqlTaskScheduler.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.CustomControls.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.NetEnterpriseServers.ExceptionMessageBox.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.IntegrationServices.MasterService.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.IntegrationServices.MasterServiceClient.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.Practices.TransientFaultHandling.Core.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.IntegrationServices.Scale.ResourceProvider.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.IntegrationServices.Scale.ScaleoutContract.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.IntegrationServices.ScaleOut.Telemetry.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.IntegrationServices.ScaleOut.Utilities.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.IntegrationService.Hadoop.Common.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.IntegrationService.HadoopComponents.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.IntegrationService.HadoopConnections.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.IntegrationService.HadoopEnumerators.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.IntegrationService.HadoopTasks.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.ExceptionMessageBox.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlTools.Telemetry.Interop.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.Ssdqs.Component.DataCorrection.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.Ssdqs.Component.DataQualityConnectionManager.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.WindowsAzure.Configuration.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.WindowsAzure.Storage.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.WindowsAzure.StorageClient.dll"
 
# Throws exceptions but likes to be added
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.Data.Services.Client.dll" -ErrorAction Stop
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.DataTransfer.Common.dll" -ErrorAction Stop
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.DataTransfer.DataContracts.dll" -ErrorAction Stop
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.AnalysisServices.AppLocal.Tabular.dll" -ErrorAction Stop
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.Management.SmoMetadataProvider.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.Hadoop.Avro.dll"
 
# Can't load, won't load
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.Data.DataFeedClient.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.DataTransfer.ClientLibrary.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.ADONETDest.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.ADONETSrc.dllv"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.BulkInsertTask.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.DataReaderDest.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.DataStreaming.Dest.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.DTSPipelineWrap.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.IntegrationServices.RuntimeTelemetry.dll"
Add-Type -Path "$script:PSModuleRoot\bin\smo\Microsoft.SqlServer.MaintenancePlanTasks.dll"
#>

}

if ($script:serialImport) {
    $scriptBlock.Invoke($script:PSModuleRoot, "$script:DllRoot\smo", (-not $script:strictSecurityMode))
}
else {
    $script:smoRunspace = [System.Management.Automation.PowerShell]::Create()
    if ($script:smoRunspace.Runspace.Name) {
        try { $script:smoRunspace.Runspace.Name = "dbatools-import-smo" }
        catch { }
    }
    $script:smoRunspace.AddScript($scriptBlock).AddArgument($script:PSModuleRoot).AddArgument("$script:DllRoot\smo").AddArgument((-not $script:strictSecurityMode))
    $script:smoRunspace.BeginInvoke()
}