How to convert a PowerShell script from local exchange service to Live@Edu / O365

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I am looking for a count of how many emails the Teacher (emailFrom) sent to the student (emailTo)
When I run the powershell script against the local exchange for users in that domain, it works just fine. When I run a modified version against outlook.com - I get 0 results… even when I know for fact the a particular teacher sent a particular student an email.
1. I think I am executing the PowerShell MessageTracking incorrectly when not on our local exchange… but where / how?
2. Also, how can I filter by day?
The purpose/goal is to quantify the correspondence between teachers and students in any given course, and the date filtering is to report on trends of teachers having different levels of contact at start, during, and finishing of courses.
FOR LOCAL EXCHANGE TRACKING:
DateTimedateFrom= DAY WE ARE INTERESTED IN TRACKING;
stringemail= EMAIL ADDRESS WE ARE INTERESTED IN TRACKING;
Runspace CurrentRunspace;
Uri sUri =newUri("https://{our local OWA public website}/powershell");
string shellUri ="http://schemas.microsoft.com/powershell/Microsoft.Exchange";
string userName ="{localDomain\ourDomainAdmin}";
string pass ="ABCdef123";
PSCredential creds =newPSCredential(userName, SecureThisPassword(pass));
WSManConnectionInfo connectionInfo =newWSManConnectionInfo(sUri, shellUri, creds);
connectionInfo.AuthenticationMechanism =AuthenticationMechanism.Basic;
connectionInfo.MaximumConnectionRedirectionCount = 20;
connectionInfo.OperationTimeout = 300000;
CurrentRunspace =RunspaceFactory.CreateRunspace(connectionInfo);
PSCommand command =newPSCommand();
command.AddCommand("Get-MessageTrackingLog");
command.AddParameter("Server","ourexchangeserverfqdn.ourdomain.domain");
command.AddParameter("Start", dateFrom.ToString());
command.AddParameter("End", dateFrom.AddDays(1).ToString());
command.AddParameter("sender", email);
command.AddParameter("EventId","SEND");
powershell.Commands = command;
// associate the runspace with powershell
powershell.Runspace = CurrentRunspace;
// invoke the powershell to obtain the results
Collection<PSObject> results = powershell.Invoke();
return results.Count;

THIS RETURNS THE NUMBER OF EMAILS SENT BY THIS USER – FOR THAT DAY.
WORKS JUST FINE
------
FOR LIVE@EDU / O365 EXCHANGE MESSAGE TRACKING:
DateTimedateFrom= DAY WE ARE INTERESTED IN TRACKING;
stringemailFrom = TEACHERS EMAIL ADDRESS WE ARE INTERESTED IN TRACKING;
stringemailTo = STUDENTS EMAIL RECIPIENT WE ARE INTERESTED IN TRACKING;
Runspace CurrentRunspace;
Uri sUri =newUri("https://ps.outlook.com/powershell");
string shellUri ="http://schemas.microsoft.com/powershell/Microsoft.Exchange";
string userName = "ourLiveEduAministratorAccount@ourowndomain.edu";
string pass ="ABCdef123";
PSCredential creds =newPSCredential(userName, SecureThisPassword(pass));
WSManConnectionInfo connectionInfo =newWSManConnectionInfo(sUri, shellUri, creds);
connectionInfo.AuthenticationMechanism =AuthenticationMechanism.Basic;
connectionInfo.MaximumConnectionRedirectionCount = 20;
connectionInfo.OperationTimeout = 300000;
CurrentRunspace =RunspaceFactory.CreateRunspace(connectionInfo);
PSCommand command =newPSCommand();
command.AddCommand("Search-MessageTrackingReport");
command.AddParameter("BypassDelegateChecking");
command.AddParameter("Identity", emailFrom);
command.AddParameter("Recipients", emailTo);
powershell.Commands = command;
// associate the runspace with powershell
powershell.Runspace = CurrentRunspace;
// invoke the powershell to obtain the results
Collection<PSObject> results = powershell.Invoke();
return results.Count;
I get 0 results from invoking that PowerShell command.
Thank you in advance for any assistance in helping to query Live@Edu / O365 Exchange Web Services for Message Tracking info for day-targeted sent/received tracking.

View the full article
 
Back
Top