?
Solved

Help getting mailbox size for a group of users using Powershell

Posted on 2012-08-22
3
Medium Priority
?
2,039 Views
Last Modified: 2012-08-23
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
0
Comment
Question by:ndalmolin_13
3 Comments
 
LVL 13

Expert Comment

by:Xaelian
ID: 38320925
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

0
 
LVL 6

Accepted Solution

by:
slidingfox earned 2000 total points
ID: 38322868
$Users = Get-qaduser –department facilities | select-Object -expand logonname
foreach ($User in $Users) {Get-MailboxStatistics -Identity $user -Server mail01}

Open in new window

0
 
LVL 16

Expert Comment

by:Rajitha Chimmani
ID: 38324195
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}
0

Featured Post

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Loops Section Overview
Screencast - Getting to Know the Pipeline

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question