33function Get-MessageTrackingGUI {
44$Icon = Initialize-MTGIcon
55
6- # Connect to Exchange 2016
7- function Connect-Exchange {
8- if ($SessionEx ) {
9- Remove-PSSession - Session$SessionEx
10- }
11-
12- $Uri = " http://" + $Config.PSConnect + " /PowerShell/"
13- $SessionEx = New-PSSession - ConfigurationName Microsoft.Exchange- ConnectionUri$Uri - Authentication Kerberos- ErrorAction SilentlyContinue
14- if ($SessionEx ) {
15- Import-PSSession $SessionEx - DisableNameChecking- AllowClobber
16- }
17- }
18-
196# Visual change PSCommandText field
207function Set-PSCommandText
218 {
@@ -43,20 +30,6 @@ function Get-MessageTrackingGUI {
4330$PSCommand.Text = $PSCommand.Text.TrimEnd (' ' )
4431 }
4532
46- function Get-TrackingLog {
47- if ($CBServers.IsChecked ) {
48- $Fields = " "
49- $Config.Fields.F | ForEach-Object {
50- $Fields += $_ + ' ,'
51- }
52- $Fields = $Fields.TrimEnd (' ,' )
53- $Servers.SelectedItems | ForEach-Object {
54- $Command = $PSCommand.Text + ' -Server "' + $_.ToString ()+ ' " | Select-Object' + $Fields
55- Invoke-Expression - Command$Command
56- }
57- }
58- }
59-
6033function Set-ConfigForm {
6134$PSConnect.Text = $Config.PSConnect
6235
@@ -222,7 +195,7 @@ function Get-MessageTrackingGUI {
222195if ($PSConnect.Text ) {
223196if ($Config.PSConnect -ne $PSConnect.Text ) {
224197$Config.PSConnect = $PSConnect.Text
225- Connect-Exchange
198+ Connect-MTGExchange
226199 }
227200 }
228201else {
@@ -410,15 +383,15 @@ function Get-MessageTrackingGUI {
410383
411384# Buttons
412385$BTSearch.Add_Click ({
413- Get-TrackingLog | Out-GridView
386+ Get-MTGTrackingLog | Out-GridView
414387 })
415388$BTExport.Add_Click ({
416389$Path = " $ ( $env: LOCALAPPDATA ) \ExchangeTrackingGUI"
417390if (! (Test-Path $Path ) ) {
418391$null = New-Item $Path - ItemType Directory
419392 }
420393$File = " $Path \Export.csv"
421- Get-TrackingLog | ConvertTo-Csv - NoTypeInformation> $File
394+ Get-MTGTrackingLog | ConvertTo-Csv - NoTypeInformation> $File
422395Invoke-Item $File
423396 })
424397$BTConfig.Add_Click ({
@@ -437,7 +410,7 @@ function Get-MessageTrackingGUI {
437410Set-ConfigForm
438411
439412# Connect to Exchange 2016
440- Connect-Exchange
413+ Connect-MTGExchange
441414
442415# Show Main form
443416$XMLForm.ShowDialog ()| Out-Null