Answered by:
unable to export username (sameaccountname) with mailbox size

Question
-
hi,
i am using this command to export all users with their name , user id (sameaccountname),mailbox size , database but samaccountname is coming as blank
Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | Select-Object DisplayName,SamAccountName,TotalItemSize,Database | Export-Csv c:\temp\size.csv
can anyone guide me how i can get the user ids as welll with mailbox size and database name
- Edited by Balal Ahmad Monday, July 24, 2017 10:05 AM
Monday, July 24, 2017 10:05 AM
Answers
-
Hi Balal
You need a foreach to be able to get the Samaccount name as this is not part of Get-MailboxStatistics you will also need a blank arrays to capture each properties. The below should work. The only problem i have had with the below is that you have to have powershell V3 or above to add the append command to export-csv.$mailboxes = get-mailbox -resultsize unlimited foreach ($mailbox in $mailboxes) { $Results=@() $properties = @{ SAMAccountName = $mailbox.sAMAccountName displayName = $mailbox.displayName TotalItemSize = (get-mailboxstatistics -id $mailbox.distinguishedname).totalitemsize ItemCount = (get-mailboxstatistics -id $mailbox.distinguishedname).ItemCount Database = $mailbox.Database } $Results += New-Object psobject -Property $properties $Results | select SAMAccountName,displayName,TotalItemSize,ItemCount,Database | Export-Csv c:\Temp\MAilboxExport.csv -NoTypeInformation -Append }
- Marked as answer by Balal Ahmad Tuesday, July 25, 2017 4:36 AM
Monday, July 24, 2017 4:29 PM
All replies
-
Get-MailboxStatistics does not have "SamAccountName". Use "DisplayName" or "alias".
\_(ツ)_/
- Edited by jrv Monday, July 24, 2017 10:25 AM
Monday, July 24, 2017 10:20 AM -
display name i already have , i need the user id , i tried Alias but still its giving blank values
Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | Select-Object DisplayName,Alias,TotalItemSize,Database | Export-Csv c:\temp\size.csv
Monday, July 24, 2017 10:34 AM -
You will have to use a foreach loop to capture the SamAccountName from get-mailbox.
\_(ツ)_/
Monday, July 24, 2017 10:45 AM -
can you please send me the complete command ?Monday, July 24, 2017 10:53 AM
-
1
Get-MailboxStatistics | where {$_.ObjectClass –eq “Mailbox”} | Sort-Object TotalItemSize –Descending | ft @{label=”User”;expression={$_.DisplayName}},@{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}},@{label=”Items”;
expression={$_.ItemCount}},@{label=”Storage Limit”;expression={$_.StorageLimitStatus}} -auto
try this too..
This posting is provided "AS IS" with no warranties and confers no rights! Always test ANY suggestion in a test environment before implementing! http://sesaitech.blogspot.in/
Monday, July 24, 2017 11:00 AM -
1
Get-MailboxStatistics | where {$_.ObjectClass –eq “Mailbox”} | Sort-Object TotalItemSize –Descending | ft @{label=”User”;expression={$_.DisplayName}},@{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}},@{label=”Items”;
expression={$_.ItemCount}},@{label=”Storage Limit”;expression={$_.StorageLimitStatus}} -auto
try this too..
This posting is provided "AS IS" with no warranties and confers no rights! Always test ANY suggestion in a test environment before implementing! http://sesaitech.blogspot.in/
\_(ツ)_/
Monday, July 24, 2017 11:02 AM -
can you please send me the complete command ?
PowerShell has a new utility that can be used to learn about commands and syntax. You should try it as it will help you solve many problems:
help ForEach-Object -full
\_(ツ)_/
Monday, July 24, 2017 11:04 AM -
its asking for identity even i m typing nothing happen , means no results on power shell
did u try with you ?
Monday, July 24, 2017 11:13 AM -
Get-MailboxStatistics -Database "Mailbox Database XXXXXXXXXXXXX" | Select DisplayName, ItemCount, TotalItemSize | Sort-Object TotalItemSize -Descending | Export-CSV C:\MBSizes.csv
Try now..i think my previous one was wrong.
This posting is provided "AS IS" with no warranties and confers no rights! Always test ANY suggestion in a test environment before implementing! http://sesaitech.blogspot.in/
Monday, July 24, 2017 11:16 AM -
Get-MailboxStatistics -Database "Mailbox Database XXXXXXXXXXXXX" | Select DisplayName, ItemCount, TotalItemSize | Sort-Object TotalItemSize -Descending | Export-CSV C:\MBSizes.csv
This posting is provided "AS IS" with no warranties and confers no rights! Always test ANY suggestion in a test environment before implementing! http://sesaitech.blogspot.in/
Monday, July 24, 2017 11:16 AM -
Hi Balal
You need a foreach to be able to get the Samaccount name as this is not part of Get-MailboxStatistics you will also need a blank arrays to capture each properties. The below should work. The only problem i have had with the below is that you have to have powershell V3 or above to add the append command to export-csv.$mailboxes = get-mailbox -resultsize unlimited foreach ($mailbox in $mailboxes) { $Results=@() $properties = @{ SAMAccountName = $mailbox.sAMAccountName displayName = $mailbox.displayName TotalItemSize = (get-mailboxstatistics -id $mailbox.distinguishedname).totalitemsize ItemCount = (get-mailboxstatistics -id $mailbox.distinguishedname).ItemCount Database = $mailbox.Database } $Results += New-Object psobject -Property $properties $Results | select SAMAccountName,displayName,TotalItemSize,ItemCount,Database | Export-Csv c:\Temp\MAilboxExport.csv -NoTypeInformation -Append }
- Marked as answer by Balal Ahmad Tuesday, July 25, 2017 4:36 AM
Monday, July 24, 2017 4:29 PM -
Dear geoff.phillis
this is what i was looking for.
Thanks
- Edited by Balal Ahmad Tuesday, July 25, 2017 4:38 AM
Tuesday, July 25, 2017 4:36 AM