We help IT Professionals succeed at work.
Get Started

Adding users to a blank array and getting the mailbox size of each user in that array using Powershell

ndalmolin_13
ndalmolin_13 asked
on
843 Views
Last Modified: 2012-08-23
Hello Powershell Experts,
Powershell is one of those things that I don’t get to do all that often at work, so I just don’t have a great handle on the basics.  What I’m trying to accomplish today is:
1.      Get a list of users in a department
2.      For each user in that list, I want to determine the mailbox size on our Exchange server

For the first goal, I can use the following command to get the list of users:
      Get-qaduser –department sales | Select-object logonname

The command above produces a list that looks like the following:
LogonName                                                                                                                                          
---------                                                                                                                                          
emusta                                                                                                                                            
sbrown                                                                                                                                            
cflynn                                                                                                                                            
psnider                                                                                                                                            
mpalacios                                                                                                                                          
jgrubb                                                                                                                                            
jfergen                                                                                                                                            
dkiewit      

I would like the list to look like:
emusta                                                                                                                                            
sbrown                                                                                                                                            
cflynn                                                                                                                                            
psnider                                                                                                                                            
mpalacios                                                                                                                                          
jgrubb                                                                                                                                            
jfergen                                                                                                                                            
dkiewit      

I think I need to use an array to do this.  My question is how do I add each logonname to a blank array?  I know I set the blank array as:
      $users = @()

To get the mailbox size for a single user, I would do the following:
get-mailboxstatistics emusta | Select-Object @{n="User";e={$_.DisplayName}}, @{n="Mailbox Size (MB)";e={$_.totalitemsize.value.ToMB()}}

How would I run through the array of users generated in step one to get the mailbox size for each one?  Would it be something as simple as:

get-mailboxstatistics $Users | Select-Object @{n="User";e={$_.DisplayName}}, @{n="Mailbox Size (MB)";e={$_.totalitemsize.value.ToMB()}}

I’m sorry for asking such lame questions, but I’ve tried everything I can think of and any help would be appreciated.
Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE