Link to home
Start Free TrialLog in
Avatar of ndalmolin_13
ndalmolin_13Flag for United States of America

asked on

Help getting mailbox size for a group of users using Powershell

Greetings Powershell Gurus,
I have a list of users that I generated with the following command:

Get-qaduser –department sales | select-Object logonname

The list of users looks like the following:

LogonName                                                                                                      
---------                                                                                                      
emusta                                                                                                        
sbrown                                                                                                        
cflynn                                                                                                        
psnider                                                                                                        
mpalacios                                                                                                      
jgrubb                                                                                                        
jfergen                                                                                                        
dkiewit

I would like to now find the mailbox size for these users.  I know that I’m going to use the get-mailboxstatistics commandlet.  I thought the following would work:

$Users = Get-qaduser –department facilities | select-Object logonname
foreach ($User in $Users) {Get-MailboxStatistics -Identity $user -Server mail01}

When I run the command above, I get the following error that I’m having trouble working through:

Get-MailboxStatistics : Cannot bind parameter 'Identity'. Cannot convert the "@{LogonName=emusta}" value of type "Selected.Quest.ActiveRoles.ArsPow
erShellSnapIn.Data.ArsUserObject" to type "Microsoft.Exchange.Configuration.Tasks.GeneralMailboxIdParameter".
At line:3 char:59
+ foreach ($User in $Users) {Get-MailboxStatistics -Identity <<<<  $user -Server mail01}
    + CategoryInfo          : InvalidArgument: (:) [Get-MailboxStatistics], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Exchange.Management.MapiTasks.GetMailboxStatistics

Any ideas on what I’m doing wrong here.  Any help would be greatly appreciated.

Thanks,
Nick
Avatar of Xaelian
Xaelian
Flag of Belgium image

You can use following. Use have to change some parts. But just read the commentary and you know what you need to change and what it does.

#AD Setting for Multi Domain Forest
Set-ADServerSettings -ViewEntireForest $true

#Array for Reporting Objects
$Summary = @()

#Array of Requested Dept Codes Which Should AD Group Named After Them
$ADGroups = "Group1","Group2","Group3","Group4","Group5","Group6","Group7"

foreach ($ADGroup in $ADGroups)
{
#Pull AD Group Members
$dPart = (get-group $ADGroup).members

foreach ($dUser in $dPart)
{
#Get Mailbox Stats for Group Member
$mbstats = get-mailboxstatistics $dUser

#Only Report on Users with Actual Mailboxes
if($mbstats.TotalItemSize)
{
#Convert Size Into GBs
$mbsize = ("{0:N2}" -f ($mbstats.TotalItemSize.Value.ToMB()/1024))
#Create New PowerShell Object and Assign Data to It
$uEntry = new-Object PSObject
$uEntry | add-Member -memberType noteProperty -name "Display Name" -Value $mbstats.DisplayName
$uEntry | add-Member -memberType noteProperty -name "Mailbox Size (GB)" -Value $mbsize
$uEntry | add-Member -memberType noteProperty -name "Last Logon Time" -Value $mbstats.LastLogonTime
#Add Entry to Summary Array
$Summary += $uEntry
}

}

}

#Export Summary Info to CSV File
$Summary | Sort-Object {[int]$_."Mailbox Size (GB)"} -Descending | Export-CSV Mailboxes_By_AD_Group.csv -NoTypeInformation

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of slidingfox
slidingfox
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you are not restricted to use just the logonname, You can use it this way with displayname or primarysmtpaddress,

$Users = Get-qaduser –department facilities
foreach ($User in $Users) {Get-MailboxStatistics -Identity $user.displayname -Server mail01}

$Users = Get-qaduser –department facilities
foreach ($User in $Users) {Get-MailboxStatistics -Identity $user.primarysmtpaddress -Server mail01}