Advertisement
7Script

Office 365 Mail Viewer

Mar 1st, 2015
1,162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Script Created By: David Septimus
  2. # This functionality is available directly in the Office 365 OWA.
  3.  
  4. function Get-Mail
  5. {
  6.     [cmdletbinding()]
  7.     param(
  8.         $UserPrincipalName,
  9.         $Password,
  10.         $Mailbox
  11.     )
  12.     [reflection.assembly]::loadwithpartialname("System.Object.Accord.Controls.ArrayDataView") | Out-Null
  13.     $secpasswd = ConvertTo-SecureString $Password -AsPlainText -Force
  14.     $Credential = New-Object System.Management.Automation.PSCredential ($UserPrincipalName, $secpasswd)
  15.     [array]$Messages
  16.     out-host -InputObject $UserPrincipalName,$Password,$Mailbox
  17.     $MessageCount = Invoke-RestMethod -Uri "https://outlook.office365.com/api/v1.0/users('$Mailbox')/Folders/Inbox/messages?`$count" -method GET  -Credential $Credential
  18.     $array = Invoke-RestMethod -Uri "https://outlook.office365.com/api/v1.0/users('$Mailbox')/Folders/Inbox/messages" -method GET  -Credential $Credential
  19.  
  20.      $MessagesPreview = New-Object System.Collections.ArrayList
  21.      for($count = 0; $count -lt $MessageCount.value.Count; $count++){
  22.         $messageTidbits = New-Object PSObject
  23.         $messageTidbits | Add-Member -name Subject -Type NoteProperty -Value $array.value.subject[$count]
  24.         $messageTidbits | Add-Member -Name Sender -Type NoteProperty -Value  $array.value.sender[$count].EmailAddress.Address
  25.         $messageTidbits | Add-Member -Name Preview -Type NoteProperty -Value $array.value.bodypreview[$count]
  26.         $messageTidbits | Add-Member -Name ID -Type NoteProperty -Value $array.Value.ID[$count]
  27.         $MessagesPreview.Add($messageTidbits)
  28.      }
  29.    
  30.            
  31.     $EmailList.DataSource = $MessagesPreview
  32.     $EmailList.refresh()
  33. }
  34.  
  35. #####################################
  36. ###          Message Window
  37.  
  38. ######################################
  39.  
  40. #------------------------------------------------------------------------
  41. # Source File Information (DO NOT MODIFY)
  42. # Source ID: 601f787c-7ba6-4299-b8fa-2d1255fc7487
  43. # Source File: C:\Users\it\Documents\SAPIEN\PowerShell Studio 2014\Files\web.psf
  44. #------------------------------------------------------------------------
  45. #region File Recovery Data (DO NOT MODIFY)
  46. <#RecoveryData:
  47. vggAAB+LCAAAAAAABAC9Vl1v2jAUfZ+0/2D5GUEgBKgUIrXpKk0rGxpVu7fKSS7Mqz+Q7UCzXz8H
  48. BwaFNrRqUaTI174nx+fe4yThT0jlAlRxSQxBdqCpFEPcwdHnTwiFPxSdUUHYFWXwnXCIlpA053oa
  49. tvZWXH7yB1KDTDGHIZ4U2gBv3lGRyaVuXknF3b2BDi010G1F32165dVAcc5MrmAoIDeKsAYa5wmj
  50. 6TcobuQDiGHS75MgDXrtM78L3uAMI2G3MsQj0JrM4JbCEhRG6W/KMmXzcSyFUZJpJ89ueKzkHJQp
  51. KmDMKAgzoX8BR8Gg20B+rxO21knPgEr5ONrhrMVMDFFmLDU1VjCOYssKapIqAFGLvYFHs+FDzxF+
  52. WdhnVohrSTIclVVezd6Xcdhajdfp9Z27g+RC2RDUh/fPuixxVO2XurdfmkuZPlihlLG9guwnX8uU
  53. uPLbrXpHAEZUUJ5zZ4+OBXWOQTl7bEk6AlPjwAOeIMlXkcGjBR3K3jaDrVHObRhLPmdgINvZ3P3e
  54. 8hOjtJxT3HnfCc61Bm77C3qdW80UUeWXERHWsuXTm+e5kXxV/v++8Y/1jd9Opv4g6JHM73XBt5I3
  55. TE+ZuU6lYjR5B3e+wOL0nYLj3c9cPWP5aTgNkSJLKmZv4fL8aTDtT9vtLPCIT+q5fnF2Gk1U2QMi
  56. VTEBtaApvKllr1YXSwUnkVepsm8cK+0DtG1C91YJW9v/K9E/a320T74IAAA=#>
  57. #endregion
  58.  
  59. <#
  60.     .NOTES
  61.     --------------------------------------------------------------------------------
  62.      Code generated by:  SAPIEN Technologies, Inc., PowerShell Studio 2014 v4.1.74
  63.      Generated on:       11/14/2014 1:09 PM
  64.      Generated by:       David Septimus
  65.     --------------------------------------------------------------------------------
  66.     .DESCRIPTION
  67.         GUI script generated by PowerShell Studio 2014
  68. #>
  69. #----------------------------------------------
  70. #region Application Functions
  71. #----------------------------------------------
  72.  
  73.  
  74. function Call-web_psf {
  75.  
  76.     #----------------------------------------------
  77.     #region Import the Assemblies
  78.     #----------------------------------------------
  79.     [void][reflection.assembly]::Load('mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
  80.     [void][reflection.assembly]::Load('System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
  81.     [void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
  82.     [void][reflection.assembly]::Load('System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
  83.     [void][reflection.assembly]::Load('System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
  84.     [void][reflection.assembly]::Load('System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
  85.     [void][reflection.assembly]::Load('System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
  86.     [void][reflection.assembly]::Load('System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
  87.     [void][reflection.assembly]::Load('System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
  88.     #endregion Import Assemblies
  89.  
  90.     #----------------------------------------------
  91.     #region Generated Form Objects
  92.     #----------------------------------------------
  93.     [System.Windows.Forms.Application]::EnableVisualStyles()
  94.     $MessageViewer = New-Object 'System.Windows.Forms.Form'
  95.     $webbrowser1 = New-Object 'System.Windows.Forms.WebBrowser'
  96.     $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
  97.     #endregion Generated Form Objects
  98.  
  99.     #----------------------------------------------
  100.     # User Generated Script
  101.     #----------------------------------------------
  102.     function OpenMessage($message) {
  103.    
  104.    
  105.    
  106.         function OnApplicationLoad {
  107.             #Note: This function is not called in Projects
  108.             #Note: This function runs before the form is created
  109.             #Note: To get the script directory in the Packager use: Split-Path $hostinvocation.MyCommand.path
  110.             #Note: To get the console output in the Packager (Windows Mode) use: $ConsoleOutput (Type: System.Collections.ArrayList)
  111.             #Important: Form controls cannot be accessed in this function
  112.             #TODO: Add modules and custom code to validate the application load
  113.        
  114.             return $true #return true for success or false for failure
  115.         }
  116.    
  117.    
  118.         function OnApplicationExit {
  119.             #Note: This function is not called in Projects
  120.             #Note: This function runs after the form is closed
  121.             #TODO: Add custom code to clean up and unload modules when the application exits
  122.        
  123.             $script:ExitCode = 0 #Set the exit code for the Packager
  124.         }
  125.    
  126.         #region Control Helper Functions
  127.         function Load-DataGridView
  128.         {
  129.             <#
  130.             .SYNOPSIS
  131.                 This functions helps you load items into a DataGridView.
  132.    
  133.             .DESCRIPTION
  134.                 Use this function to dynamically load items into the DataGridView control.
  135.    
  136.             .PARAMETER  DataGridView
  137.                 The ComboBox control you want to add items to.
  138.    
  139.             .PARAMETER  Item
  140.                 The object or objects you wish to load into the ComboBox's items collection.
  141.        
  142.             .PARAMETER  DataMember
  143.                 Sets the name of the list or table in the data source for which the DataGridView is displaying data.
  144.    
  145.             #>
  146.             Param (
  147.                 [ValidateNotNull()]
  148.                 [Parameter(Mandatory=$true)]
  149.                 [System.Windows.Forms.DataGridView]$DataGridView,
  150.                 [ValidateNotNull()]
  151.                 [Parameter(Mandatory=$true)]
  152.                 $Item,
  153.                 [Parameter(Mandatory=$false)]
  154.                 [string]$DataMember
  155.             )
  156.             $DataGridView.SuspendLayout()
  157.             $DataGridView.DataMember = $DataMember
  158.        
  159.             if ($Item -is [System.ComponentModel.IListSource]`
  160.             -or $Item -is [System.ComponentModel.IBindingList] -or $Item -is [System.ComponentModel.IBindingListView] )
  161.             {
  162.                 $DataGridView.DataSource = $Item
  163.             }
  164.             else
  165.             {
  166.                 $array = New-Object System.Collections.ArrayList
  167.            
  168.                 if ($Item -is [System.Collections.IList])
  169.                 {
  170.                     $array.AddRange($Item)
  171.                 }
  172.                 else
  173.                 {  
  174.                     $array.Add($Item)  
  175.                 }
  176.                 $DataGridView.DataSource = $array
  177.             }
  178.        
  179.             $DataGridView.ResumeLayout()
  180.         }
  181.    
  182.         function ConvertTo-DataTable
  183.         {
  184.             <#
  185.                 .SYNOPSIS
  186.                     Converts objects into a DataTable.
  187.        
  188.                 .DESCRIPTION
  189.                     Converts objects into a DataTable, which are used for DataBinding.
  190.        
  191.                 .PARAMETER  InputObject
  192.                     The input to convert into a DataTable.
  193.        
  194.                 .PARAMETER  Table
  195.                     The DataTable you wish to load the input into.
  196.        
  197.                 .PARAMETER RetainColumns
  198.                     This switch tells the function to keep the DataTable's existing columns.
  199.            
  200.                 .PARAMETER FilterWMIProperties
  201.                     This switch removes WMI properties that start with an underline.
  202.        
  203.                 .EXAMPLE
  204.                     $DataTable = ConvertTo-DataTable -InputObject (Get-Process)
  205.             #>
  206.             [OutputType([System.Data.DataTable])]
  207.             param(
  208.             [ValidateNotNull()]
  209.             $InputObject,
  210.             [ValidateNotNull()]
  211.             [System.Data.DataTable]$Table,
  212.             [switch]$RetainColumns,
  213.             [switch]$FilterWMIProperties)
  214.        
  215.             if($Table -eq $null)
  216.             {
  217.                 $Table = New-Object System.Data.DataTable
  218.             }
  219.    
  220.             if($InputObject-is [System.Data.DataTable])
  221.             {
  222.                 $Table = $InputObject
  223.             }
  224.             else
  225.             {
  226.                 if(-not $RetainColumns -or $Table.Columns.Count -eq 0)
  227.                 {
  228.                     #Clear out the Table Contents
  229.                     $Table.Clear()
  230.    
  231.                     if($InputObject -eq $null){ return } #Empty Data
  232.                
  233.                     $object = $null
  234.                     #find the first non null value
  235.                     foreach($item in $InputObject)
  236.                     {
  237.                         if($item -ne $null)
  238.                         {
  239.                             $object = $item
  240.                             break  
  241.                         }
  242.                     }
  243.    
  244.                     if($object -eq $null) { return } #All null then empty
  245.                
  246.                     #Get all the properties in order to create the columns
  247.                     foreach ($prop in $object.PSObject.Get_Properties())
  248.                     {
  249.                         if(-not $FilterWMIProperties -or -not $prop.Name.StartsWith('__'))#filter out WMI properties
  250.                         {
  251.                             #Get the type from the Definition string
  252.                             $type = $null
  253.                        
  254.                             if($prop.Value -ne $null)
  255.                             {
  256.                                 try{ $type = $prop.Value.GetType() } catch {}
  257.                             }
  258.    
  259.                             if($type -ne $null) # -and [System.Type]::GetTypeCode($type) -ne 'Object')
  260.                             {
  261.                                 [void]$table.Columns.Add($prop.Name, $type)
  262.                             }
  263.                             else #Type info not found
  264.                             {
  265.                                 [void]$table.Columns.Add($prop.Name)    
  266.                             }
  267.                         }
  268.                     }
  269.                
  270.                     if($object -is [System.Data.DataRow])
  271.                     {
  272.                         foreach($item in $InputObject)
  273.                         {  
  274.                             $Table.Rows.Add($item)
  275.                         }
  276.                         return  @(,$Table)
  277.                     }
  278.                 }
  279.                 else
  280.                 {
  281.                     $Table.Rows.Clear()
  282.                 }
  283.            
  284.                 foreach($item in $InputObject)
  285.                 {      
  286.                     $row = $table.NewRow()
  287.                
  288.                     if($item)
  289.                     {
  290.                         foreach ($prop in $item.PSObject.Get_Properties())
  291.                         {
  292.                             if($table.Columns.Contains($prop.Name))
  293.                             {
  294.                                 $row.Item($prop.Name) = $prop.Value
  295.                             }
  296.                         }
  297.                     }
  298.                     [void]$table.Rows.Add($row)
  299.                 }
  300.             }
  301.    
  302.             return @(,$Table)  
  303.         }
  304.         #endregion
  305.    
  306.         #region Search Function
  307.         function SearchGrid()
  308.         {
  309.             $RowIndex = 0
  310.             $ColumnIndex = 0
  311.             $seachString = $textboxSearch.Text
  312.        
  313.             if($seachString -eq "")
  314.             {
  315.                 return
  316.             }
  317.        
  318.             if($datagridviewResults.SelectedCells.Count -ne 0)
  319.             {
  320.                 $startCell = $datagridviewResults.SelectedCells[0];
  321.                 $RowIndex = $startCell.RowIndex
  322.                 $ColumnIndex = $startCell.ColumnIndex + 1
  323.             }
  324.        
  325.             $columnCount = $datagridviewResults.ColumnCount
  326.             $rowCount = $datagridviewResults.RowCount
  327.             for(;$RowIndex -lt $rowCount; $RowIndex++)
  328.             {
  329.                 $Row = $datagridviewResults.Rows[$RowIndex]
  330.            
  331.                 for(;$ColumnIndex -lt $columnCount; $ColumnIndex++)
  332.                 {
  333.                     $cell = $Row.Cells[$ColumnIndex]
  334.                
  335.                     if($cell.Value -ne $null -and $cell.Value.ToString().IndexOf($seachString, [StringComparison]::OrdinalIgnoreCase) -ne -1)
  336.                     {
  337.                         $datagridviewResults.CurrentCell = $cell
  338.                         return
  339.                     }
  340.                 }
  341.            
  342.                 $ColumnIndex = 0
  343.             }
  344.        
  345.             $datagridviewResults.CurrentCell = $null
  346.             [void][System.Windows.Forms.MessageBox]::Show("The search has reached the end of the grid.","String not Found")
  347.        
  348.         }
  349.         #endregion
  350.    
  351.         $FormEvent_Load={
  352.             #TODO: Initialize Form Controls here
  353.             $webbrowser1.DocumentText = "$message";
  354.         }
  355.    
  356.         $buttonExit_Click={
  357.             #TODO: Place custom script here
  358.             $MessageViewer.Close()
  359.         }
  360.    
  361.         $buttonQuery_Click={
  362.             #TODO: Place custom script here
  363.         #   ---------------------------------
  364.         #   Sample Code to Load Grid
  365.         #   ---------------------------------
  366.         #   $processes = Get-WmiObject Win32_Process -Namespace "Root\CIMV2"
  367.         #   Load-DataGridView -DataGridView $datagridviewResults -Item $processes
  368.         #   ---------------------------------
  369.         #   Sample Code to Load Sortable Data
  370.         #   ---------------------------------
  371.         #   $processes = Get-WmiObject Win32_Process -Namespace "Root\CIMV2"
  372.         #   $table = ConvertTo-DataTable -InputObject $processes -FilterWMIProperties
  373.             #   Load-DataGridView -DataGridView $datagridviewResults -Item $table
  374.        
  375.    
  376.         }
  377.    
  378.    
  379.         $webbrowser1_DocumentCompleted=[System.Windows.Forms.WebBrowserDocumentCompletedEventHandler]{
  380.         #Event Argument: $_ = [System.Windows.Forms.WebBrowserDocumentCompletedEventArgs]
  381.             #TODO: Place custom script here
  382.        
  383.         }
  384.    
  385.         # --End User Generated Script--
  386.         #----------------------------------------------
  387.         #region Generated Events
  388.         #----------------------------------------------
  389.    
  390.         $Form_StateCorrection_Load=
  391.         {
  392.             #Correct the initial state of the form to prevent the .Net maximized form issue
  393.             $MessageViewer.WindowState = $InitialFormWindowState
  394.         }
  395.    
  396.         $Form_Cleanup_FormClosed=
  397.         {
  398.             #Remove all event handlers from the controls
  399.             try
  400.             {
  401.                 $webbrowser1.remove_DocumentCompleted($webbrowser1_DocumentCompleted)
  402.                 $MessageViewer.remove_Load($FormEvent_Load)
  403.                 $MessageViewer.remove_Load($Form_StateCorrection_Load)
  404.                 $MessageViewer.remove_FormClosed($Form_Cleanup_FormClosed)
  405.             }
  406.             catch [Exception]
  407.             { }
  408.         }
  409.         #endregion Generated Events
  410.  
  411.         #----------------------------------------------
  412.         #region Generated Form Code
  413.         #----------------------------------------------
  414.         $MessageViewer.SuspendLayout()
  415.         #
  416.         # MessageViewer
  417.         #
  418.         $MessageViewer.Controls.Add($webbrowser1)
  419.         $MessageViewer.ClientSize = '584, 362'
  420.         $MessageViewer.Name = "MessageViewer"
  421.         $MessageViewer.StartPosition = 'CenterScreen'
  422.         $MessageViewer.Text = "Message Viewer"
  423.         $MessageViewer.add_Load($FormEvent_Load)
  424.         #
  425.         # webbrowser1
  426.         #
  427.         $webbrowser1.Dock = 'Fill'
  428.         $webbrowser1.Location = '0, 0'
  429.         $webbrowser1.MinimumSize = '20, 20'
  430.         $webbrowser1.Name = "webbrowser1"
  431.         $webbrowser1.Size = '584, 362'
  432.         $webbrowser1.TabIndex = 5
  433.         $webbrowser1.add_DocumentCompleted($webbrowser1_DocumentCompleted)
  434.         $MessageViewer.ResumeLayout()
  435.         #endregion Generated Form Code
  436.  
  437.         #----------------------------------------------
  438.  
  439.         #Save the initial state of the form
  440.         $InitialFormWindowState = $MessageViewer.WindowState
  441.         #Init the OnLoad event to correct the initial state of the form
  442.         $MessageViewer.add_Load($Form_StateCorrection_Load)
  443.         #Clean up the control events
  444.         $MessageViewer.add_FormClosed($Form_Cleanup_FormClosed)
  445.         #Show the Form
  446.         return $MessageViewer.ShowDialog()
  447.  
  448.     } #End Function
  449.  
  450.     #Call OnApplicationLoad to initialize
  451.     if((OnApplicationLoad) -eq $true)
  452.     {
  453.         #Call the form
  454.         Call-web_psf | Out-Null
  455.         #Perform cleanup
  456.         OnApplicationExit
  457.     }
  458. }
  459. #################################
  460. ####         End Message Window
  461.  
  462. ##############################
  463.  
  464. <#
  465.     .NOTES
  466.     --------------------------------------------------------------------------------
  467.      Code generated by:  SAPIEN Technologies, Inc., PowerShell Studio 2014 v4.1.74
  468.      Generated on:       11/13/2014 4:38 PM
  469.      Generated by:       David Septimus
  470.     --------------------------------------------------------------------------------
  471.     .DESCRIPTION
  472.         GUI script generated by PowerShell Studio 2014
  473. #>
  474. #----------------------------------------------
  475. #region Application Functions
  476. #----------------------------------------------
  477.  
  478. function OnApplicationLoad {
  479.     #Note: This function is not called in Projects
  480.     #Note: This function runs before the form is created
  481.     #Note: To get the script directory in the Packager use: Split-Path $hostinvocation.MyCommand.path
  482.     #Note: To get the console output in the Packager (Windows Mode) use: $ConsoleOutput (Type: System.Collections.ArrayList)
  483.     #Important: Form controls cannot be accessed in this function
  484.     #TODO: Add modules and custom code to validate the application load
  485.    
  486.     return $true #return true for success or false for failure
  487. }
  488.  
  489. function OnApplicationExit {
  490.     #Note: This function is not called in Projects
  491.     #Note: This function runs after the form is closed
  492.     #TODO: Add custom code to clean up and unload modules when the application exits
  493.    
  494.     $script:ExitCode = 0 #Set the exit code for the Packager
  495. }
  496.  
  497. #endregion Application Functions
  498.  
  499. #----------------------------------------------
  500. # Generated Form Function
  501. #----------------------------------------------
  502. function Call-form_psf {
  503.  
  504.     #----------------------------------------------
  505.     #region Import the Assemblies
  506.     #----------------------------------------------
  507.     [void][reflection.assembly]::Load('mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
  508.     [void][reflection.assembly]::Load('System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
  509.     [void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
  510.     [void][reflection.assembly]::Load('System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
  511.     [void][reflection.assembly]::Load('System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
  512.     [void][reflection.assembly]::Load('System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
  513.     [void][reflection.assembly]::Load('System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
  514.     [void][reflection.assembly]::Load('System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
  515.     [void][reflection.assembly]::Load('System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
  516.     #endregion Import Assemblies
  517.  
  518.     #----------------------------------------------
  519.     #region Generated Form Objects
  520.     #----------------------------------------------
  521.     [System.Windows.Forms.Application]::EnableVisualStyles()
  522.     $formMailViewer = New-Object 'System.Windows.Forms.Form'
  523.     $labelPassword = New-Object 'System.Windows.Forms.Label'
  524.     $labelUserName = New-Object 'System.Windows.Forms.Label'
  525.     $labelMailbox = New-Object 'System.Windows.Forms.Label'
  526.     $password = New-Object 'System.Windows.Forms.MaskedTextBox'
  527.     $UserName = New-Object 'System.Windows.Forms.TextBox'
  528.     $Mailbox = New-Object 'System.Windows.Forms.TextBox'
  529.     $GetMailButton = New-Object 'System.Windows.Forms.Button'
  530.     $EmailList = New-Object 'System.Windows.Forms.DataGridView'
  531.     $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
  532.     #endregion Generated Form Objects
  533.  
  534.     #----------------------------------------------
  535.     # User Generated Script
  536.     #----------------------------------------------
  537.    
  538.    
  539.    
  540.    
  541.    
  542.    
  543.    
  544.     $formMailViewer_Load={
  545.         #TODO: Initialize Form Controls here
  546.        
  547.     }
  548.    
  549.     #region Control Helper Functions
  550.     function Load-DataGridView
  551.     {
  552.         <#
  553.         .SYNOPSIS
  554.             This functions helps you load items into a DataGridView.
  555.    
  556.         .DESCRIPTION
  557.             Use this function to dynamically load items into the DataGridView control.
  558.    
  559.         .PARAMETER  DataGridView
  560.             The ComboBox control you want to add items to.
  561.    
  562.         .PARAMETER  Item
  563.             The object or objects you wish to load into the ComboBox's items collection.
  564.        
  565.         .PARAMETER  DataMember
  566.             Sets the name of the list or table in the data source for which the DataGridView is displaying data.
  567.    
  568.         #>
  569.         Param (
  570.             [ValidateNotNull()]
  571.             [Parameter(Mandatory=$true)]
  572.             [System.Windows.Forms.DataGridView]$DataGridView,
  573.             [ValidateNotNull()]
  574.             [Parameter(Mandatory=$true)]
  575.             $Item,
  576.             [Parameter(Mandatory=$false)]
  577.             [string]$DataMember
  578.         )
  579.         $DataGridView.SuspendLayout()
  580.         $DataGridView.DataMember = $DataMember
  581.        
  582.         if ($Item -is [System.ComponentModel.IListSource]`
  583.         -or $Item -is [System.ComponentModel.IBindingList] -or $Item -is [System.ComponentModel.IBindingListView] )
  584.         {
  585.             $DataGridView.DataSource = $Item
  586.         }
  587.         else
  588.         {
  589.             $array = New-Object System.Collections.ArrayList
  590.            
  591.             if ($Item -is [System.Collections.IList])
  592.             {
  593.                 $array.AddRange($Item)
  594.             }
  595.             else
  596.             {  
  597.                 $array.Add($Item)  
  598.             }
  599.             $DataGridView.DataSource = $array
  600.         }
  601.        
  602.         $DataGridView.ResumeLayout()
  603.     }
  604.     #endregion
  605.    
  606.     $labelMailbox_Click={
  607.         #TODO: Place custom script here
  608.        
  609.     }
  610.  
  611.     $GetMailButton_Click={
  612.         #TODO: Place custom script here
  613.         Get-Mail -UserPrincipalName $UserName.Text -Password $password.Text -Mailbox $Mailbox.Text
  614.  
  615.     }  
  616.  
  617.     $EmailList_MouseDoubleClick=[System.Windows.Forms.MouseEventHandler]{
  618.     #Event Argument: $_ = [System.Windows.Forms.MouseEventArgs]
  619.         #TODO: Place custom script here
  620.        
  621.     }
  622.    
  623.     # --End User Generated Script--
  624.     #----------------------------------------------
  625.     #region Generated Events
  626.     #----------------------------------------------
  627.    
  628.     $Form_StateCorrection_Load=
  629.     {
  630.         #Correct the initial state of the form to prevent the .Net maximized form issue
  631.         $formMailViewer.WindowState = $InitialFormWindowState
  632.     }
  633.    
  634.     $Form_Cleanup_FormClosed=
  635.     {
  636.         #Remove all event handlers from the controls
  637.         try
  638.         {
  639.             $labelMailbox.remove_Click($labelMailbox_Click)
  640.             $EmailList.remove_MouseDoubleClick($EmailList_MouseDoubleClick)
  641.             $formMailViewer.remove_Load($formMailViewer_Load)
  642.             $formMailViewer.remove_Load($Form_StateCorrection_Load)
  643.             $formMailViewer.remove_FormClosed($Form_Cleanup_FormClosed)
  644.         }
  645.         catch [Exception]
  646.         { }
  647.     }
  648.     #endregion Generated Events
  649.  
  650.     #----------------------------------------------
  651.     #region Generated Form Code
  652.     #----------------------------------------------
  653.     $formMailViewer.SuspendLayout()
  654.     #
  655.     # formMailViewer
  656.     #
  657.     $formMailViewer.Controls.Add($labelPassword)
  658.     $formMailViewer.Controls.Add($labelUserName)
  659.     $formMailViewer.Controls.Add($labelMailbox)
  660.     $formMailViewer.Controls.Add($password)
  661.     $formMailViewer.Controls.Add($UserName)
  662.     $formMailViewer.Controls.Add($Mailbox)
  663.     $formMailViewer.Controls.Add($GetMailButton)
  664.     $formMailViewer.Controls.Add($EmailList)
  665.     $formMailViewer.ClientSize = '1048, 539'
  666.     $formMailViewer.Name = "formMailViewer"
  667.     $formMailViewer.Text = "Mail Viewer for Office 365"
  668.     $formMailViewer.add_Load($formMailViewer_Load)
  669.     #
  670.     # labelPassword
  671.     #
  672.     $labelPassword.Location = '794, 120'
  673.     $labelPassword.Name = "labelPassword"
  674.     $labelPassword.Size = '63, 23'
  675.     $labelPassword.TabIndex = 7
  676.     $labelPassword.Text = "Password"
  677.     #
  678.     # labelUserName
  679.     #
  680.     $labelUserName.Location = '794, 93'
  681.     $labelUserName.Name = "labelUserName"
  682.     $labelUserName.Size = '63, 23'
  683.     $labelUserName.TabIndex = 6
  684.     $labelUserName.Text = "User Name"
  685.     #
  686.     # labelMailbox
  687.     #
  688.     $labelMailbox.Location = '794, 66'
  689.     $labelMailbox.Name = "labelMailbox"
  690.     $labelMailbox.Size = '63, 23'
  691.     $labelMailbox.TabIndex = 5
  692.     $labelMailbox.Text = "Mailbox"
  693.     $labelMailbox.add_Click($labelMailbox_Click)
  694.     #
  695.     # password
  696.     #
  697.     $password.Location = '863, 117'
  698.     $password.Name = "password"
  699.     $password.PasswordChar = '•'
  700.     $password.Size = '157, 20'
  701.     $password.TabIndex = 4
  702.     #
  703.     # UserName
  704.     #
  705.     $UserName.Location = '863, 90'
  706.     $UserName.Name = "UserName"
  707.     $UserName.Size = '157, 20'
  708.     $UserName.TabIndex = 3
  709.     #
  710.     # Mailbox
  711.     #
  712.     $Mailbox.Location = '863, 63'
  713.     $Mailbox.Name = "Mailbox"
  714.     $Mailbox.Size = '157, 20'
  715.     $Mailbox.TabIndex = 2
  716.     #
  717.     # GetMailButton
  718.     #
  719.     $GetMailButton.Location = '945, 143'
  720.     $GetMailButton.Name = "GetMailButton"
  721.     $GetMailButton.Size = '75, 23'
  722.     $GetMailButton.TabIndex = 1
  723.     $GetMailButton.Text = "Get Mail"
  724.     $GetMailButton.UseVisualStyleBackColor = $True
  725.     $GetMailButton.add_Click($GetMailButton_Click)
  726.     #
  727.     # EmailList
  728.     #
  729.     $EmailList.AllowUserToAddRows = $False
  730.     $EmailList.AllowUserToDeleteRows = $False
  731.     $EmailList.AllowUserToOrderColumns = $True
  732.     $EmailList.ColumnHeadersHeightSizeMode = 'AutoSize'
  733.     $EmailList.Location = '12, 42'
  734.     $EmailList.Name = "EmailList"
  735.     $EmailList.ReadOnly = $True
  736.     $EmailList.SelectionMode = 'FullRowSelect'
  737.     $EmailList.Size = '767, 467'
  738.     $EmailList.TabIndex = 0
  739.     $EmailList.add_MouseDoubleClick($EmailList_MouseDoubleClick)
  740.     $formMailViewer.ResumeLayout()
  741.     #endregion Generated Form Code
  742.  
  743.     #----------------------------------------------
  744.  
  745.     #Save the initial state of the form
  746.     $InitialFormWindowState = $formMailViewer.WindowState
  747.     #Init the OnLoad event to correct the initial state of the form
  748.     $formMailViewer.add_Load($Form_StateCorrection_Load)
  749.     #Clean up the control events
  750.     $formMailViewer.add_FormClosed($Form_Cleanup_FormClosed)
  751.     #Show the Form
  752.     return $formMailViewer.ShowDialog()
  753.  
  754. } #End Function
  755.  
  756. #Call OnApplicationLoad to initialize
  757. if((OnApplicationLoad) -eq $true)
  758. {
  759.     #Call the form
  760.     Call-form_psf | Out-Null
  761.     #Perform cleanup
  762.     OnApplicationExit
  763. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement