Chat with us, powered by LiveChat

Blog

Back

Tracking Messages in Office 365 with Out-GridView

1 Oct 2013 by Dan Rose

One of the really cool things about Powershell is that there are so many great cmdlets that do so many great things. One of those that really ticks all the boxes for me is Out-GridView, this is especially useful if used it to display lists of Message information from Office 365.
Rather than sending your script outputs to files or dumping information to the screen, you can pipe a simple array of data into a window that give you the added ability of performing searches, filtering and sorting.
Tracking messages is probably a good candidate for using this cmdlet especially if you have large amounts of data to sort through that may require filtering.
Sorting messages by received date.
Screen Shot 2013-10-01 at 12.34.57
Add filter criteria, message to/from a specific IP address.
Screen Shot 2013-10-01 at 12.34.35
Filter on specific text, finding messages by subject.
Screen Shot 2013-10-01 at 12.33.03
I’ve included a simple script, so you can see this in action. This script will connect to the Exchange Online and retrieve your companies messages and display them in a grid-view. In order for you to get this information, you need to ensure that your tenant is running on the latest version of Office 365 (Wave 15) and that you are using an account that has administrative privileges to perform the search.
<#
.PURPOSE
Script will display a output of messages sent/received from within a tenant using
the Exchange Online.
. EXAMPLES
PS> Get-MessageTraceReportPS.ps1
.OUTPUT
RecipientAddress
SenderAddress
Subject
Status
Received
ToIP
FromIP
Size
MessageTraceId
MessageId
.NOTES
Your Office 365 tenant must be running the latest (wave15) version and your account
must have the correct administrative rights to retrieve this data.
.AUTHOR
Dan Rose (Cogmotive)
#>
function ConnectTo-ExchangeOnline
{
<# .SYNOPSIS Connects to Exchange Online with tenant credentials .INPUT Tenant Username/Password .RETURN None #>
# Get Credentials
$Office365Credentials = Get-Credential
# Create remote Powershell session
$Script:Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $Office365credentials -Authentication Basic –AllowRedirection
# Import the session
Import-PSSession $Session -AllowClobber | Out-Null
}
ConnectTo-ExchangeOnline
Write-Host "Retrieving message details. Please Wait.."
$MessageList = @()
try {
#Iterate through all properties
foreach ($node in Get-MessageTrace)
{
$ObjProperties = New-Object PSObject
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "RecipientAddress" -Value $node.RecipientAddress
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "SenderAddress" -Value $node.SenderAddress
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Subject" -Value $node.Subject
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Received" -Value $node.Received
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "ToIP" -Value $node.ToIP
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "FromIP" -Value $node.FromIP
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Size" -Value $node.Size
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Status" -Value $node.Status
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "MessageTraceId" -Value $node.MessageTraceId
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "MessageId" -Value $node.MessageId
$MessageList += $objProperties
}
$MessageList |
Out-GridView -Title "My Message Status Report"
}
catch {
Write-Host "Error: $($Error[0].Exception)"
}