ES1_ObjectsAndTypes.psm1

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
<#    
.NOTES
 ===========================================================================
 
 Copyright � 2018 Dell Inc. or its subsidiaries. All Rights Reserved.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
        http://www.apache.org/licenses/LICENSE-2.0
 ===========================================================================

    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
    WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
  WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
  IF THIS CODE AND INFORMATION IS MODIFIED, THE ENTIRE RISK OF USE OR RESULTS IN
  CONNECTION WITH THE USE OF THIS CODE AND INFORMATION REMAINS WITH THE USER.
 ===========================================================================
.DESCRIPTION
  A collection of functions to load SourceOne COM/.NET datatypes and ENUMs
#>



Function Add-ES1Types {
<#
.SYNOPSIS
 Add the SourceOne COM, .NET objects and Datatypes to the current Powershell context
.DESCRIPTION
 Add the SourceOne COM, .NET objects and Datatypes to the current Powershell Context
 SourceOne objects are all 32 bit COM/.NET objects, therefore must only be used in
 32 bit PowerShell hosts. Starting with SourceOne 7.0 all COM/.NET objects also
 require .NET 4.0 or greater. PowerShell 2.0 loads .NET 2 by defualt therefore these objects and
 types can only be used with PowerShell 3.0 or greater.
 
.EXAMPLE
 Add-ES1Types

 Description
 -----------------------
 Loads available SourceOne COM, .NET objects and Datatypes to the current context
#>


[OutputType('System.Boolean')]
[CmdletBinding()]
Param( )

BEGIN{
    [bool] $success = $false
}

PROCESS
{
    
    $POSHVersion=Get-POSHVersionAndArchitecture
    #Write-Host "Powershell Version : $POSHVersion"
    if ($POSHVersion.Architecture -eq '64-bit')
    {
        Write-Error 'This must run in a 32 bit PowerShell !'
        Throw 'This must run in a 32 bit PowerShell !'
       return $success
    }

    # I changed the manifest to require Powershell 4 or greater now, so this may never show
    if ($POSHVersion.Version -eq '2.0')
    {
        Write-Error 'Requires PowerShell 4.0 or greater !'
        Throw 'Requires PowerShell 4.0 or greater !'
       return $success
    }

    try {
        # Powershell 3 and greater
        # This works with SourceOne 7.1.1
        # May have to adjust the Version strings for other versions of S1
        add-type -assemblyname "EMC.Interop.ExBase, Culture=neutral,Version=6.6.3.8,PublicKeyToken=D3CC2CEEAFB73BC1" -ErrorAction SilentlyContinue
        add-type -assemblyname "EMC.Interop.ExSTLContainers, Culture=neutral,Version=6.6.3.1,PublicKeyToken=D3CC2CEEAFB73BC1"  -ErrorAction SilentlyContinue
        add-type -assemblyname "EMC.Interop.ExDataSet, Culture=neutral,Version=6.6.3.1,PublicKeyToken=D3CC2CEEAFB73BC1"  -ErrorAction SilentlyContinue
        add-type -assemblyname "EMC.Interop.ExASBaseAPI, Culture=neutral,Version=6.6.3.1,PublicKeyToken=D3CC2CEEAFB73BC1" -ErrorAction SilentlyContinue
        add-type -assemblyname "EMC.Interop.ExJDFAPI, Culture=neutral,Version=6.6.3.2,PublicKeyToken=D3CC2CEEAFB73BC1"  -ErrorAction SilentlyContinue
        add-type -AssemblyName "EMC.Interop.ExASAdminAPI, Culture=neutral,Version=6.6.3.1,PublicKeyToken=D3CC2CEEAFB73BC1" -ErrorAction SilentlyContinue
        add-type -AssemblyName "EMC.Interop.ExProviderGW, Culture=neutral,Version=6.6.3.1,PublicKeyToken=D3CC2CEEAFB73BC1" -ErrorAction SilentlyContinue

        $success = $true
    }
    catch {
        
        Write-Host  'Failed loading SourceOne Objects and Types ! ' -foregroundcolor red
        Write-Host  'This command can only be run on a SourceOne machine where SourceOne COM objects have been registered' -foregroundcolor red
        Throw $_
    }

    $success
}


END {}

}

Function Show-ES1COMObjects {
<#
.SYNOPSIS
 Displays a list of the SourceOne COM/.NET objects, classes that are registered on the system
.DESCRIPTION
 Displays a list of the SourceOne COM/.NET objects, classes that are registered on the system.
 The registered objects may differ depending on the SourceOne machine and installed roles.
 The objects are enumerated from the HKLM:\Software\Classes registry key and some regex filtering is applied
 to display only objects in known EMC and SourceOne namespaces.

.EXAMPLE
 Show-ES1COMObjects

#>

[CmdletBinding()]
Param( )

BEGIN{
}

PROCESS
{
    Get-ChildItem HKLM:\Software\Classes -ErrorAction SilentlyContinue | Where-Object {
       (($_.PSChildName -like '*.CoEx*') -or ($_.PSChildName -like 'EMC.*')) -and (Test-Path -Path "$($_.PSPath)\CLSID") 
    } | ft -AutoSize | Out-String -Width 10000 

}

END {}
}

Function Show-EMCEnums {
<#
.SYNOPSIS
 Display a list of enum types and values only in the "EMC" namespace in the current context
 
.DESCRIPTION
 Display a list of enum types and values only in the "EMC" namespace in the current context

.EXAMPLE
 Show-EMCEnums
 
Type Name Value
---- ---- -----
EMC.Interop.ExBase.exCoreTaskTypes exCoreTaskTypes_Undefined 0
EMC.Interop.ExBase.exCoreTaskTypes exCoreTaskTypes_Diagnostic 1
EMC.Interop.ExBase.exCoreTaskTypes exCoreTaskTypes_Journal 2

#>

[CmdletBinding()]
Param( )

BEGIN{
try {
         [bool] $loaded = Add-ES1Types #-ErrorAction SilentlyContinue

        if (-not $loaded )
        {
            Write-Error 'Error loading SourceOne Objects and Types'
            break
        }
    }
    catch
    {
        Write-Error $_ 
        break
    }
}

PROCESS
{

    get-type -IsEnum -Namespace EMC* | Get-EnumValues | ft -AutoSize | Out-String -Width 10000


}

END {}
}

Function Show-EMCAvailableTypes {
<#
.SYNOPSIS
 Display a list of the objects in the "EMC" namespace in the current context
 Does not include "enum" types
.DESCRIPTION
 Display a list of the objects in the "EMC" namespace in the current context
 Does not include "enum" types

.EXAMPLE
 Show-EMCAvailableTypes
 
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False IExBase
True False IExFolder
True False IExVector
True False CoExVector
True False CoExVectorClass System.__ComObject
True False IExMap
True False CoExMap
True False CoExMapClass System.__ComObject

#>

[CmdletBinding()]
Param( )

BEGIN{
try {
         [bool] $loaded = Add-ES1Types #-ErrorAction SilentlyContinue

        if (-not $loaded )
        {
            Write-Error 'Error loading SourceOne Objects and Types'
            break
        }
    }
    catch
    {
        Write-Error $_ 
        break
    }
}

PROCESS
{

    get-type -Namespace EMC* | where {$_.BaseType -ne [System.Enum]} |ft -AutoSize | Out-String -Width 10000


}

END {}
}


function Get-Type {
    <#
    .SYNOPSIS
        Get exported types in the current session

    .DESCRIPTION
        Get exported types in the current session

    .PARAMETER Module
        Filter on Module. Accepts wildcard

    .PARAMETER Assembly
        Filter on Assembly. Accepts wildcard

    .PARAMETER FullName
        Filter on FullName. Accepts wildcard
    
    .PARAMETER Namespace
        Filter on Namespace. Accepts wildcard
    
    .PARAMETER BaseType
        Filter on BaseType. Accepts wildcard

    .PARAMETER IsEnum
        Filter on IsEnum.

    .EXAMPLE
        #List the full name of all Enums in the current session
        Get-Type -IsEnum $true | Select -ExpandProperty FullName | Sort -Unique

    .EXAMPLE
        #Connect to a web service and list all the exported types
            
        #Connect to the web service, give it a namespace we can search on
            $weather = New-WebServiceProxy -uri "http://www.webservicex.net/globalweather.asmx?wsdl" -Namespace GlobalWeather

        #Search for the namespace
            Get-Type -NameSpace GlobalWeather
        
            IsPublic IsSerial Name BaseType
            -------- -------- ---- --------
            True False MyClass1ex_net_globalweather_asmx_wsdl System.Object
            True False GlobalWeather System.Web.Services.Protocols.SoapHttpClientProtocol
            True True GetWeatherCompletedEventHandler System.MulticastDelegate
            True False GetWeatherCompletedEventArgs System.ComponentModel.AsyncCompletedEventArgs
            True True GetCitiesByCountryCompletedEventHandler System.MulticastDelegate
            True False GetCitiesByCountryCompletedEventArgs System.ComponentModel.AsyncCompletedEventArgs

    .FUNCTIONALITY
        Computers
 .NOTES
  Adapted from:
  https://gallery.technet.microsoft.com/scriptcenter/Get-Type-Get-exported-fee19cf7
    #>

    [cmdletbinding()]
    param(
        [string]$Module = '*',
        [string]$Assembly = '*',
        [string]$FullName = '*',
        [string]$Namespace = '*',
        [string]$BaseType = '*',
        [switch]$IsEnum
    )
    
    #Build up the Where statement
        $WhereArray = @('$_.IsPublic')
        if($Module -ne "*"){$WhereArray += '$_.Module -like $Module'}
        if($Assembly -ne "*"){$WhereArray += '$_.Assembly -like $Assembly'}
        if($FullName -ne "*"){$WhereArray += '$_.FullName -like $FullName'}
        if($Namespace -ne "*"){$WhereArray += '$_.Namespace -like $Namespace'}
        if($BaseType -ne "*"){$WhereArray += '$_.BaseType -like $BaseType'}
        #This clause is only evoked if IsEnum is passed in
        if($PSBoundParameters.ContainsKey("IsEnum")) { $WhereArray += '$_.IsENum -like $IsENum' }
    
    #Give verbose output, convert where string to scriptblock
        $WhereString = $WhereArray -Join " -and "
        $WhereBlock = [scriptblock]::Create( $WhereString )
        Write-Verbose "Where ScriptBlock: { $WhereString }"

    #Invoke the search!
        [AppDomain]::CurrentDomain.GetAssemblies() | ForEach-Object {
            Write-Verbose "Getting types from $($_.FullName)"
            Try
            {
                $_.GetExportedTypes()
            }
            Catch
            {
                Write-Verbose "$($_.FullName) error getting Exported Types: $_"
                $null
            }

        } | Where-Object -FilterScript $WhereBlock
}

function Get-EnumValues {  
     <#
    .SYNOPSIS
        Return list of names and values for an enumeration object
     
    .DESCRIPTION
        Return list of names and values for an enumeration object
     
    .PARAMETER Type
        Pass in an actual type, or a string for the type name.
    .EXAMPLE
        Get-EnumValues system.dayofweek
    .EXAMPLE
        [System.DayOfWeek] | Get-EnumValues
     .FUNCTIONALITY
        General Command
 .NOTES
 Adapted from
 https://gist.github.com/RamblingCookieMonster/3e01f840e4160136523d#file-get-enumvalues-ps1

    #>

    [cmdletbinding()]
    param(
        [parameter( Mandatory = $True,
                    ValueFromPipeline = $True,
                    ValueFromPipelineByPropertyName = $True)]
        [Alias("FullName")]
        $Type
    )

    Process
    {
        [enum]::getvalues($type) |
            Select @{name="Type";  expression={$Type.ToString()}},
                   @{name="Name";  expression={$_.ToString()}},
                   @{name="Value"; expression={$_.value__}}
    }
}


Export-ModuleMember -Function Show-EMCAvailableTypes, Show-EMCEnums,Add-ES1Types,Show-ES1COMObjects