When I pass a single mailbox to Get-Mailbox, it works fine, but when I pass all mailboxes (as in this example) the last couple columns are blank. I can’t figure out what I’m doing wrong!!<\/p>\n
get-mailbox -resultsize unlimited | Select-Object DisplayName,UserPrincipalName,UseDatabaseRetentionDefaults,RetainDeletedItemsFor,IsMailboxEnabled,RecipientLimits,UseDatabaseQuotaDefaults,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,MaxSendSize,MaxReceiveSize,@{n=\"TotalItemSize\";e={(Get-MailboxStatistics $_).TotalItemSize}},@{n=\"TotalDeletedItemSize\";e={(Get-MailboxStatistics $_).TotalDeletedItemSize}},@{n=\"StorageLimitStatus\";e={(Get-MailboxStatistics $_).StorageLimitStatus}},@{n=\"ItemCount\";e={(Get-MailboxStatistics $_).ItemCount}} | out-gridview -title \"report\"\n<\/code><\/pre>","upvoteCount":8,"answerCount":11,"datePublished":"2014-08-22T15:57:49.000Z","author":{"@type":"Person","name":"joshhand3134","url":"https://community.spiceworks.com/u/joshhand3134"},"acceptedAnswer":{"@type":"Answer","text":"
Advertisement
And here’s the final script I came up with:<\/p>\n
$mboxes = get-mailbox -resultsize unlimited | Select-Object DisplayName,UserPrincipalName,UseDatabaseRetentionDefaults,RetainDeletedItemsFor,IsMailboxEnabled,RecipientLimits,UseDatabaseQuotaDefaults,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,MaxSendSize,MaxReceiveSize\nForEach($mbox in $mboxes)\n{\n\t$mboxStats = Get-MailboxStatistics $mbox.DisplayName\n\t$mbox | Add-Member -Name TotalItemSize -MemberType NoteProperty -Value $mboxStats.TotalItemSize\n\t$mbox | Add-Member -Name TotalDeletedItemSize -MemberType NoteProperty -Value $mboxStats.TotalDeletedItemSize\n\t$mbox | Add-Member -Name StorageLimitStatus -MemberType NoteProperty -Value $mboxStats.StorageLimitStatus\n\t$mbox | Add-Member -Name ItemCount -MemberType NoteProperty -Value $mboxStats.ItemCount\n}\n$mboxes | Out-GridView\n<\/code><\/pre>\n
Advertisement
You could use the Select-Object like you were before, but I just like the Add-Member for the ease of reading.<\/p>\n
EDIT: Fixed two mistakes<\/p>","upvoteCount":3,"datePublished":"2014-08-22T16:30:49.000Z","url":"https://community.spiceworks.com/t/powershell-and-exchange-2010/332784/5","author":{"@type":"Person","name":"anthony","url":"https://community.spiceworks.com/u/anthony"}},"suggestedAnswer":[{"@type":"Answer","text":"
When I pass a single mailbox to Get-Mailbox, it works fine, but when I pass all mailboxes (as in this example) the last couple columns are blank. I can’t figure out what I’m doing wrong!!<\/p>\n
get-mailbox -resultsize unlimited | Select-Object DisplayName,UserPrincipalName,UseDatabaseRetentionDefaults,RetainDeletedItemsFor,IsMailboxEnabled,RecipientLimits,UseDatabaseQuotaDefaults,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,MaxSendSize,MaxReceiveSize,@{n=\"TotalItemSize\";e={(Get-MailboxStatistics $_).TotalItemSize}},@{n=\"TotalDeletedItemSize\";e={(Get-MailboxStatistics $_).TotalDeletedItemSize}},@{n=\"StorageLimitStatus\";e={(Get-MailboxStatistics $_).StorageLimitStatus}},@{n=\"ItemCount\";e={(Get-MailboxStatistics $_).ItemCount}} | out-gridview -title \"report\"\n<\/code><\/pre>","upvoteCount":8,"datePublished":"2014-08-22T15:57:49.000Z","url":"https://community.spiceworks.com/t/powershell-and-exchange-2010/332784/1","author":{"@type":"Person","name":"joshhand3134","url":"https://community.spiceworks.com/u/joshhand3134"}},{"@type":"Answer","text":"It might be a thing to make it a script rather than a single liner! That would make it much easier to troubleshoot, so let me give that a go real quick.<\/p>","upvoteCount":2,"datePublished":"2014-08-22T16:18:10.000Z","url":"https://community.spiceworks.com/t/powershell-and-exchange-2010/332784/2","author":{"@type":"Person","name":"anthony","url":"https://community.spiceworks.com/u/anthony"}},{"@type":"Answer","text":"
I confirmed the issue and did a google search. Others have the same problem. I also, now remember having this issue in the past too. Get-MailboxStatistics doesn’t like the pipeline. Loop thru the mailboxes instead.<\/p>\n
$results = ForEach($mb in (get-mailbox -resultsize unlimited)){\n $mb | Select-Object ....\n}\n$results | Out-GridView\n\n<\/code><\/pre>","upvoteCount":3,"datePublished":"2014-08-22T16:27:06.000Z","url":"https://community.spiceworks.com/t/powershell-and-exchange-2010/332784/3","author":{"@type":"Person","name":"craigduff","url":"https://community.spiceworks.com/u/craigduff"}},{"@type":"Answer","text":"Ah, and you know, I think I figured out why. For each of your Get-MailboxStatistics, use $_.UserPrincipalName. Since you are modifying the original Get-Mailbox cmdlet, you are not passing a complete mailbox object through the pipeline, so Get-MailboxStatistics is not able to resolve it.<\/p>\n
get-mailbox -resultsize unlimited | Select-Object DisplayName,UserPrincipalName,UseDatabaseRetentionDefaults,RetainDeletedItemsFor,IsMailboxEnabled,RecipientLimits,UseDatabaseQuotaDefaults,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,MaxSendSize,MaxReceiveSize,@{n=\"TotalItemSize\";e={(Get-MailboxStatistics $_.UserPrincipalName).TotalItemSize}},@{n=\"TotalDeletedItemSize\";e={(Get-MailboxStatistics $_.UserPrincipalName).TotalDeletedItemSize}},@{n=\"StorageLimitStatus\";e={(Get-MailboxStatistics $_.UserPrincipalName).StorageLimitStatus}},@{n=\"ItemCount\";e={(Get-MailboxStatistics $_.UserPrincipalName).ItemCount}} | out-gridview -title \"report\"\n<\/code><\/pre>\nEDIT: I take that back… I can’t actually get it to work. cduff is right!<\/p>","upvoteCount":1,"datePublished":"2014-08-22T16:29:44.000Z","url":"https://community.spiceworks.com/t/powershell-and-exchange-2010/332784/4","author":{"@type":"Person","name":"anthony","url":"https://community.spiceworks.com/u/anthony"}},{"@type":"Answer","text":"
@Twon<\/span> of An:<\/p>\nThat script is returning 1 result, and also produces this error:<\/p>\n
Cannot process argument transformation on parameter 'Identity'. Cannot convert value \"\" to type \"Microsoft.Exchange.Configuration.Tasks.GeneralMailboxIdParameter\". Error: \"Parameter values of type Microsoft.Exchange.Configuration.Tasks.GeneralMailboxIdParameter can't be empty. Specify a value, and try again.\nParameter name: identity\"\n + CategoryInfo : InvalidData: (:) [Get-MailboxStatistics], ParameterBindin...mationException\n + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-MailboxStatistics\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2014-08-22T17:29:15.000Z","url":"https://community.spiceworks.com/t/powershell-and-exchange-2010/332784/6","author":{"@type":"Person","name":"joshhand3134","url":"https://community.spiceworks.com/u/joshhand3134"}},{"@type":"Answer","text":"Ah, you know what, your mailboxes might not all have the UserPrincipalName property filled in. Try using DisplayName instead.<\/p>\n
I’ve edited the original script to reflect that.<\/p>","upvoteCount":1,"datePublished":"2014-08-22T17:37:14.000Z","url":"https://community.spiceworks.com/t/powershell-and-exchange-2010/332784/7","author":{"@type":"Person","name":"anthony","url":"https://community.spiceworks.com/u/anthony"}},{"@type":"Answer","text":"
That fixed the error! Still just 1 result appearing in the grid window, though.<\/p>","upvoteCount":0,"datePublished":"2014-08-22T17:44:00.000Z","url":"https://community.spiceworks.com/t/powershell-and-exchange-2010/332784/8","author":{"@type":"Person","name":"joshhand3134","url":"https://community.spiceworks.com/u/joshhand3134"}},{"@type":"Answer","text":"