I am trying to get mailbox statistics from Office 365. This is the current script:
# Get credentials
$O365Creds = New-Object -Typename System.Management.Automation.PSCredential -ArgumentList "reports@o365.example.com",$SecurePassword
# Create session
$O365Session = New-PSSession –ConfigurationName Microsoft.Exchange -ConnectionURI https://ps.outlook.com/powershell -Credential $O365Creds -Authentication Basic -AllowRedirection
Import-PSSession $O365Session -AllowClobber
# Create report
Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | FT @{n="UserID";e={(Get-Mailbox $_.LegacyDN).Name}},LastLogonTime | Out-File -FilePath o365_logons.csv -Encoding utf8 -append
Looking at the memory usage, seems like Get-Mailbox -ResultSize Unlimited
is loaded into memory before pipping it; over 1GB of memory usage. Most of the time it just times out. This is terribly inefficient since I am only interested in two columns.
Anyone have any suggestions on how to complete this task in a more efficient way?