|
30 | 30 |
|
31 | 31 | #Requires -Version 5.1
|
32 | 32 |
|
33 |
| -#region Embedded Resource |
34 |
| - |
35 |
| -#endregion Embedded Resource |
36 |
| - |
37 | 33 | #region Variables
|
38 | 34 | #region XAML markup
|
39 | 35 | [xml]$Xaml = '<Window
|
|
111 | 107 | </Style>
|
112 | 108 | <Style TargetType="{x:Type DataGrid}">
|
113 | 109 | <Setter Property="Grid.Row" Value="2" />
|
| 110 | + <Setter Property="HorizontalAlignment" Value="Stretch"/> |
| 111 | + <Setter Property="VerticalAlignment" Value="Stretch"/> |
114 | 112 | <Setter Property="VerticalScrollBarVisibility" Value="Auto"/>
|
115 |
| - <Setter Property="HorizontalScrollBarVisibility" Value="Disabled"/> |
| 113 | + <Setter Property="HorizontalScrollBarVisibility" Value="Disabled"/> |
116 | 114 | <Setter Property="AutoGenerateColumns" Value="True"/>
|
117 | 115 | <Setter Property="IsReadOnly" Value="True"/>
|
118 | 116 | <Setter Property="GridLinesVisibility" Value="All"/>
|
119 | 117 | <Setter Property="CanUserReorderColumns" Value="False"/>
|
120 | 118 | <Setter Property="RowHeaderWidth" Value="0"/>
|
121 | 119 | <Setter Property="HeadersVisibility" Value="Column"/>
|
122 | 120 | <Setter Property="ColumnWidth" Value="*"/>
|
123 |
| - <Setter Property="Visibility" Value="Collapsed"/> |
| 121 | + <Setter Property="Visibility" Value="Collapsed"/> |
124 | 122 | </Style>
|
125 | 123 | <Style TargetType="{x:Type StackPanel}" x:Key="TextBoxPanel">
|
126 | 124 | <Setter Property="Orientation" Value="Horizontal" />
|
|
238 | 236 | <TextBox Name="StartDateTextBox"
|
239 | 237 | Grid.Column="1"
|
240 | 238 | MaxLength="19"
|
241 |
| - TabIndex="1" /> |
| 239 | + TabIndex="1" |
| 240 | + Tag="Start" /> |
242 | 241 | </Grid>
|
243 | 242 | </StackPanel>
|
244 | 243 | <StackPanel Style="{StaticResource TextBoxPanel}">
|
|
255 | 254 | <TextBox Name="EndDateTextBox"
|
256 | 255 | Grid.Column="1"
|
257 | 256 | MaxLength="19"
|
258 |
| - TabIndex="2" /> |
| 257 | + TabIndex="2" |
| 258 | + Tag="End" /> |
259 | 259 | </Grid>
|
260 | 260 | </StackPanel>
|
261 | 261 | <StackPanel Style="{StaticResource TextBoxPanel}">
|
|
271 | 271 |
|
272 | 272 | <TextBox Name="SenderTextBox"
|
273 | 273 | Grid.Column="1"
|
274 |
| - TabIndex="3" /> |
| 274 | + TabIndex="3" |
| 275 | + Tag="Sender" /> |
275 | 276 | </Grid>
|
276 | 277 | </StackPanel>
|
277 | 278 | <StackPanel Style="{StaticResource TextBoxPanel}">
|
|
287 | 288 |
|
288 | 289 | <TextBox Name="RecipientTextBox"
|
289 | 290 | Grid.Column="1"
|
290 |
| - TabIndex="4" /> |
| 291 | + TabIndex="4" |
| 292 | + Tag="Recipients" /> |
291 | 293 | </Grid>
|
292 | 294 | </StackPanel>
|
293 | 295 | <StackPanel Style="{StaticResource TextBoxPanel}">
|
|
303 | 305 |
|
304 | 306 | <TextBox Name="SubjectTextBox"
|
305 | 307 | Grid.Column="1"
|
306 |
| - TabIndex="5" /> |
| 308 | + TabIndex="5" |
| 309 | + Tag="MessageSubject" /> |
307 | 310 | </Grid>
|
308 | 311 | </StackPanel>
|
309 | 312 | <StackPanel Style="{StaticResource TextBoxPanel}">
|
|
320 | 323 |
|
321 | 324 | <ComboBox Name="EventIdTextBox"
|
322 | 325 | Grid.Column="1"
|
323 |
| - TabIndex="6"> |
| 326 | + TabIndex="6" |
| 327 | + Tag="EventId" > |
324 | 328 | </ComboBox>
|
325 | 329 | </Grid>
|
326 | 330 | </StackPanel>
|
|
354 | 358 | $MailEventId = [ordered]@{
|
355 | 359 | "All events" = "ANY"
|
356 | 360 | "DEFER: message delivery was delayed" = "DEFER"
|
357 |
| - "DELIVER: message was delivered" = "DELIVER" |
| 361 | + "DELIVER: message was delivered" = "DELIVER" |
358 | 362 | "DROP: message was dropped" = "DROP"
|
359 | 363 | "DSN: delivery status notification created" = "DSN"
|
360 |
| - "RECEIVE: message was received to SMTP" = "RECEIVE" |
| 364 | + "RECEIVE: message was received to SMTP" = "RECEIVE" |
361 | 365 | "SEND: A message was sent by SMTP" = "SEND"
|
362 | 366 | }
|
363 | 367 | $GitHubPage = "https://github.com/Inestic/PowerShell-Admin-Toys"
|
@@ -417,26 +421,46 @@ function Get-ExchangeSnapin {
|
417 | 421 |
|
418 | 422 | function Start-MessageTracking {
|
419 | 423 |
|
420 |
| - [String]$TrackingCommand = [String]::Format("Get-MessageTrackingLog -Start {0} -End {1}", $StartDateTextBox.Text, $EndDateTextBox.Text) |
421 |
| - $SenderTextBox, $RecipientTextBox, $SubjectTextBox |
422 |
| - |
| 424 | + [String]$TrackingCommand = [String]::Format("Get-MessageTrackingLog -Start ""{0}"" -End ""{1}""", $StartDateTextBox.Text, $EndDateTextBox.Text) |
| 425 | + $SenderTextBox, $RecipientTextBox, $SubjectTextBox | ForEach-Object -Process { |
| 426 | + if ($_.Text -ne [string]::Empty) { $TrackingCommand += " -{0} ""{1}"""-f $_.Tag, $_.Text } |
| 427 | + } |
423 | 428 |
|
424 |
| - #if ([string]::Empty -ne $SenderTextBox.Text) {$TrackingCommand += " -Sender ""{0}"""-f $SenderTextBox.Text} |
| 429 | + if ($EventIdTextBox.SelectedIndex -ne 0) { $TrackingCommand += " -{0} {1}"-f $EventIdTextBox.Tag, $MailEventId[$EventIdTextBox.SelectedIndex] } |
| 430 | + $TrackedMessage = New-Object System.Collections.ArrayList($null) |
| 431 | + Get-ExchangeServer | ForEach-Object -Process { |
| 432 | + $StatusBarTextBlock.Text = "Started tracking mail" |
| 433 | + [String]$ServerCommand = '{0} -Server "{1}" -ResultSize Unlimited'-f $TrackingCommand, $_.Name |
| 434 | + Invoke-Expression -Command $ServerCommand | ForEach-Object -Process { |
| 435 | + $Property = [ordered]@{} |
| 436 | + $Property.TimeStamp = $_.Timestamp |
| 437 | + $Property.Server = $_.ServerHostname.ToLower() |
| 438 | + $Property.EventId = $_.EventId |
| 439 | + $Property.Sender = $_.Sender.ToLower() |
| 440 | + $Property.Recipients = [string]::join(",",$_.recipients).ToLower() |
| 441 | + $Property.Subject = $_.MessageSubject |
| 442 | + $Property.RecipientCount = $_.RecipientCount |
| 443 | + [Void]$TrackedMessage.Add((New-Object -TypeName PSObject -Property $Property)) |
| 444 | + } |
| 445 | + } |
425 | 446 |
|
| 447 | + $StatusBarTextBlock.Text = "Found: {0}"-f $TrackedMessage.Count |
| 448 | + if ($TrackedMessage.Count -gt 0) |
| 449 | + { |
| 450 | + $FoundMailDataGrid.ItemsSource = $TrackedMessage | Sort-Object -Property Timestamp -Descending |
| 451 | + $FoundMailDataGrid.Visibility = "Visible" |
| 452 | + } |
426 | 453 |
|
427 |
| - |
428 | 454 | }
|
429 | 455 | #endregion Functions
|
430 | 456 |
|
431 | 457 | Add-Type -AssemblyName PresentationFramework
|
432 | 458 |
|
433 | 459 | $Gui = [Windows.Markup.XamlReader]::Load((New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $Xaml))
|
434 |
| -$Xaml.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process { |
435 |
| - Set-Variable -Name ($_.Name) -Value $Gui.FindName($_.Name) |
436 |
| -} |
437 |
| - |
438 |
| -$StartDateTextBox.Text = [DateTime]::Today |
439 |
| -$EndDateTextBox.Text = [DateTime]::Today.AddSeconds(-1) |
| 460 | +$Xaml.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process { Set-Variable -Name ($_.Name) -Value $Gui.FindName($_.Name) } |
| 461 | +$Today = [DateTime]::Today |
| 462 | +$StartDateTextBox.Text = "{0} {1}"-f $Today.ToShortDateString(), $Today.ToLongTimeString() |
| 463 | +$EndDateTextBox.Text = "{0} {1}"-f $Today.ToShortDateString(), $Today.AddDays(1).AddSeconds(-1).ToLongTimeString() |
440 | 464 | $EventIdTextBox.ItemsSource = $MailEventId.Keys
|
441 | 465 | $EventIdTextBox.SelectedItem = $EventIdTextBox.ItemsSource | Select-Object -First 1
|
442 | 466 | $Window.add_Loaded({Get-ExchangeSnapin})
|
|
0 commit comments