• Status: Solved
  • Priority: High
  • Security: Private
  • Views: 52
  • Last Modified:

I need some help in fixing the PowerShell to count external email count from multiple different Exchange servers.

Hi,

I need someone here to adjust and modify my PowerShell MessageTrackingLog script:

Purpose: To get the total number of top 10 external email address that was delivered to my mailbox in the past 30 days

$trackparams = @{
	Start = Get-Date -UFormat "%d.%m.%Y 00:00:00" -Date 30
	End = Get-Date
	Resultsize = 'Unlimited'
    EventId = 'DELIVER'
	Recipients = "MyEmail@Domain.com"
}

$Messages = (Get-TransportService) | Get-Messagetrackinglog @trackparams

ForEach ($Domain in (Get-AcceptedDomain).Name){
	$Messages = $Messages | where {$_.Sender -notlike "*$Domain"}
}

$Messages | 
Group-Object -Property Sender | 
Select-Object Name, Count | 
Sort-Object Count -Descending | 
Select-Object -First 10 | 
Format-Table -AutoSize

Open in new window


The problem with the above script is that I cannot change the value of Start and End date since the result will always be the same?
Note: I am running Exchange 2013 DAG of 6 servers so when I execute the script via PowerShell ISE in one of the servers, I have placed the Get-TransportService under brackets then pipe it into the Get-Messagetrackinglog script.

Any help would be greatly appreciated.

Thanks in advance.
0
Senior IT System Engineer
Asked:
Senior IT System Engineer
1 Solution
 
Mohammad Ishtyaq KhatriCommented:
change your fix parameter to variables

1. For Start Date
$start = (get-date).AddDays(-30)

Open in new window

2. For End Date
$end = Get-Date

Open in new window

1
 
Senior IT System EngineerIT ProfessionalAuthor Commented:
thanks for the quick solution man :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now