internal/functions/Method1to6.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
Function Method1to6 {
    <#
    .SYNOPSIS
    Method to list folders in the user mailbox.
     
    .DESCRIPTION
    Method to list folders in the user mailbox, showing Folder name, FolderId, Number of items, and number of subfolders.
     
    .EXAMPLE
    PS C:\> Method1to6
    lists folders in the user mailbox.
 
    #>

    [CmdletBinding()]
    param(
        # Parameters
    )
    $statusBar.Text = "Running..."
        if($radiobutton1.Checked){$Wellknownfolder = "MsgFolderRoot"}
        elseif($radiobutton2.Checked){$Wellknownfolder = "ArchiveMsgFolderRoot"}
        elseif($radiobutton3.Checked){$Wellknownfolder = "PublicFoldersRoot"}
        elseif($radiobutton5.Checked){$Wellknownfolder = "RecoverableItemsRoot"}
        elseif($radiobutton6.Checked){$Wellknownfolder = "ArchiveRecoverableItemsRoot"}
        elseif($radiobutton4.Checked){$Wellknownfolder = $txtBoxFolderID.Text}

        #listing all available folders in the mailbox
        $FolderView = New-Object Microsoft.Exchange.WebServices.Data.FolderView(100);
        if($radiobutton4.Checked)
        {
            $sourceFolderId = new-object Microsoft.Exchange.WebServices.Data.FolderId($Wellknownfolder)
            $rootfolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$sourceFolderId)
        }
        else
        {
            $rootfolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service, [Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::$Wellknownfolder)
        }
        
        $rootfolder.load()
        $array = New-Object System.Collections.ArrayList
        foreach ($folder in $rootfolder.FindFolders($FolderView) )
        {
            $i++
            $output = $folder | Select-Object DisplayName, @{N="TotalItemsCount";E={$_.TotalCount}}, @{N="# of Subfolders";E={$_.ChildFolderCount}},Id
            $array.Add($output)
            }
        $dgResults.datasource = $array
        $dgResults.AutoResizeColumns()
        $dgResults.Visible = $True
        $txtBoxResults.Visible = $False
        $PremiseForm.refresh()
        $statusBar.Text = "Ready. Folders found: $i"
        Write-PSFMessage -Level Output -Message "Task finished succesfully" -FunctionName "Method 1-6"
}