ES1_MappedFolder.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
<#    
 .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
  Functions and objects for S1 Mapped (business) Folders

#>


<#
.SYNOPSIS
 Creates a new mapped folder. No permissions are applied
.DESCRIPTION
 Creates a new mapped folder. No permissions are applied

.PARAMETER MappedFolder
 New mapped folder name
.PARAMETER Description
 Description for the new mapped folder
.PARAMETER ArchiveName
 Archive connection name of archive containing the the ArchiveFolderPath
.PARAMETER ArchiveFolderPath
 The path of the archive folder to associated with the mapped folder
.PARAMETER MappedType
 The type of the mapped folder, "Organization","Community","LegalHold", "Personal" are valid
 values. Only "Organization" is supported at this time.

.EXAMPLE
 
#>

function New-ES1MappedFolder
{
[CmdletBinding()]
PARAM( [Parameter(Mandatory=$true)]
        [string] $MappedFolder,
        [Parameter(Mandatory=$false)]
        [string] $Description,
        [Parameter(Mandatory=$true)]
        [Alias('archive')]
        [string] $ArchiveName,        
        [Parameter(Mandatory=$true)]
        [string] $ArchiveFolderPath,
        [Parameter(Mandatory=$true)]
        [ValidateSet ("Organization","Community","LegalHold", "Personal")]
        [string] $MappedType

        )

BEGIN{
        $MyDebug = $false
        # Do both these checks to take advantage of internal parsing of syntaxes like -Debug:$false
        if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("Debug") -and $PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent)
        {
            $DebugPreference = "Continue"
            Write-Debug "Debug Output activated"
            # for convenience
            $MyDebug = $true
        }

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

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

PROCESS {

    try {
        $providerGW=new-object -comobject ExProviderGW.CoExProviderGW
        
        $s1Archive = Get-ES1ArchiveConnection -ArchiveName $ArchiveName

        $fmgr=$providergw.GetFolderMgr()
        $fmgr.SetTraceInfo($Global:S1LogFile)
        [EMC.Interop.ExBase.exBusinessFolderType] $folderType = [EMC.Interop.ExBase.exBusinessFolderType]::exBusinessFolderType_Unknown

        switch ($MappedType)
        {
            Organization
            {
                $folderType = [EMC.Interop.ExBase.exBusinessFolderType]::exBusinessFolderType_Organization
            }

            default 
            {
                throw "Unsupported folder type $($MappedType)"
            }

        }

        $mappedFldr=$fmgr.CreateFolder( $folderType) 
    
        $mappedFldr.FolderId = -1
        $mappedFldr.Name = $MappedFolder
        $mappedFldr.RepositoryName= $ArchiveName
        $mappedFldr.ProviderConfigID = $s1Archive.ID
        $mappedFldr.ArchiveFolderPath = $ArchiveFolderPath
        $mappedFldr.Description  = $Description

        $results= $mappedFldr.Validate()

        # Validation errors are in the results
        foreach ($valResult in $results)
        {
                # Check the "IsWarning" attibute, false means fatal error
                if ($valResult.IsWarning -eq $false)
                {
                    throw $valResult.errorDescription
                }
    
        }
    
        $mappedFldr.Save()

    }
    catch {
        Write-Error $_
    }

}

END{}

}

<#
.SYNOPSIS
 Gets mapped folder or folders
.DESCRIPTION
 Gets mapped folder or folders

.PARAMETER MappedFolder
 Optional, if provided the name of mapped folder to get.

.EXAMPLE
 
#>

function Get-ES1MappedFolder
{
[CmdletBinding()]
PARAM( [Parameter(Mandatory=$false)]
        [string] $MappedFolder

        )

BEGIN{
        $MyDebug = $false
        # Do both these checks to take advantage of internal parsing of syntaxes like -Debug:$false
        if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("Debug") -and $PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent)
        {
            $DebugPreference = "Continue"
            Write-Debug "Debug Output activated"
            # for convenience
            $MyDebug = $true
        }

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

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

PROCESS {

    try {
        $providerGW=new-object -comobject ExProviderGW.CoExProviderGW
        
        $fmgr=$providergw.GetFolderMgr()
        $fmgr.SetTraceInfo($Global:S1LogFile)

        if ($MappedFolder)
        {
            $mappedFolders = $fmgr.FindFolderByName($MappedFolder)
        }
        else
        {
            $mappedFolders = $fmgr.EnumerateFolders([EMC.Interop.ExProviderGW.eFolderInfoLevel]::FolderEverything, 
                                            [EMC.Interop.ExBase.exBusinessFolderType]::exBusinessFolderType_All)
        }

        $mappedFolders
    }
    catch {
        Write-Error $_
    }

}

END{}

}



Export-ModuleMember -Function * -Alias *