I'm trying to get an Exchange 2010 report from a multitenant platform. The thing is I need info obtained from different cmdlets. Our client is asking for DisplayName, MailboxPlan, PrimarySMTPAddress (Get-Mailbox), TotalItemSize and LastLogonTime (Get-MailboxStatistics)
I'm trying to do this using Powershell, but I'm getting an error... can you help me find out what's wrong?
Here's the script:
$TBMailbox = Get-Mailbox -Organization organization -ResultSize Unlimited | Select-Object Identity,DisplayName,MailboxPlan,PrimarySMTPAddress
ForEach ($Mbx in $TBMailbox) {$temp += ,(Get-MailboxStatistics -Identity $Mbx.Identity | Select $Mbx.Identity,$Mbx.DisplayName,$Mbx.MailboxPlan,$Mbx.PrimarySMTPAddress,TotalItemSize,LastLogonTime)}
$temp | Export-Csv -Path "C:\Path"
I'm Getting this error:
- ForEach ($Mbx in $TBMailbox) {$temp += ,(Get-MailboxStatistics -Identity $Mbx.Identity | Select <<<< $Mbx.Identity,$Mbx.MailboxPlan,$Mbx.PrimarySMTPAddress,TotalItemSize,LastLogonTime)}
- CategoryInfo : InvalidArgument: (:) [Select-Object], NotSupportedException
- FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Commands.SelectObjectCommand Select-Object : Cannot convert Microsoft.Exchange.Data.Directory.ADObjectId to one of the following types {System.String, System. Management.Automation.ScriptBlock}. At line:1 char:96
Any thoughts?
Update
Tried a different approach, but with the same result. I think the problem here is Select-Object:
Get-Mailbox -Organization organization -ResultSize Unlimited | ForEach-Object -Process {Select-Object $_.DisplayName,$_.MailboxPlan,$_.PrimarySMTPAddress,@{n=”Size(MB)”;e = {$MBXstat = Get-MailboxStatistics -Identity $_.Identity; $MBXstat.totalItemsize.value.toMB()}},@{n="LastLogonTime";e = {$MBXstat = Get-MailboxStatistics -Identity $_.Identity; $MBXstat.lastlogontime}}} | Export-Csv "C:\report.csv"
Select
andSelect-Object -Property
, and it fails with the same error message – EdoBarroso