Trying to set up a PS script that queries O365 Exchange, checks for inbound mail, counts all inbound mail, returns count, and do the same for outbound.
Here's what I have so far, it keeps returning an identical number of inbound vs outbound messages which is 500500.
Not sure how that can be unless it's a preset maximum and I've reached the upper limit.
# initialize session
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking
# O365 Inbound/Outbound tracking
$inbound = Get-MailTrafficReport -Direction Inbound | select "MessageCount"
$inbound -replace "[()\s+]"
$i = $inbound
$(for($i=0;$i -le 1000; $i+=1){$i} ) | ForEach-Object -begin {$inbound_sum=0 }-process {$inbound_sum+=$_}
$inbound_sum
# send sum to streaming dataset?
$outbound = Get-MailTrafficReport -Direction Outbound | select "MessageCount"
$outbound -replace "[()\s+]"
$o = $outbound
$(for($o=0;$o -le 1000; $o+=1){$o} ) | ForEach-Object -begin {$outbound_sum=0 }-process {$outbound_sum+=$_}
$outbound_sum
inbound_sum = outbound_sum? What am I missing here?
I tried taking out the $0 -le 1000
in the iterator lines and it just hangs. Despite this I doubt limiting the results to 1000 is summing inbound and outbound to exactly the same number.
500 is the windows administrative account uid, seems like I've hit the administrative limit.
Measure-Object -Sum
– vrdse Feb 21 '20 at 22:15