When I run the below PowerShell script to get the list of inactive AD user account Exchange mailbox that is NOT categorized as a Shared Mailbox.
Script:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://PRODMAIL01-VM/PowerShell/ -Authentication Kerberos
Import-PSSession $Session -AllowClobber
$filter = '(Enabled -eq $false) -and (msExchRecipientTypeDetails -ne 4) -and (homeMDB -ne "$null")'
$properties = @('homeMDB', 'mailNickName', 'mail', 'DisplayName', 'SamAccountName', 'ProxyAddresses')
Get-ADUser -Filter $filter -Properties $properties |
ForEach-Object {
$stat = Get-MailboxStatistics $_.SamAccountName
$smtpAddresses = ($_.ProxyAddresses | Where-Object {$_ -like "*smtp:*" }) -replace 'smtp:'
New-Object -TypeName PSObject -Property ([ordered]@{
DisplayName = $_.DisplayName
mailNickName = $_.mailNickName
SamAccountName = $_.SamAccountName
mail = $_.mail
ProxyAddresses = $smtpAddresses -join ';'
HomeMDB = $_.homeMDB.Split(',=')[1]
MBytes = $stat.TotalItemSize.Value.ToMB()
LastLogonTime = $stat.LastLogonTime
LastLoggedOnUserAccount = $stat.SamAccountName
DisconnectDate = $stat.DisconnectDate
})
} |
Sort-Object MBytes -Descending |
Export-Csv C:\TEMP\Results.csv -NoTypeInformation
This is the error message that gets repeated thousands of times:
Method invocation failed because [Deserialized.Microsoft.Exchange.Data.ByteQuantifiedSize] does not contain a method named 'ToMB'. At line:15 char:5 + New-Object -TypeName PSObject -Property ([ordered]@{ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (ToMB:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound