get-mailbox search multiple OUs

Hi I am writing a powershell script which needs to look into multiple OUs and I have this as my Get-Mailbox search but I'm unsure how to set it to look into several OUs. This is how I am writing it so far:

foreach ($mailbox in (Get-MailBox -ResultSize Unlimited  -OrganizationalUnit "domain/Students/Students-junior/test"))

Can I simply add another -OrganizationalUnit to this line so search another OU?

Any suggestions?


Greatly appreciated
dcirona86Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TMekeelCommented:
You could loop through the OUs just like you are looping through the mailboxes.  
Store the ou's in an array if there arent many or import them from a csv.
0
TMekeelCommented:
Something like:

foreach ($ou in $ouList)
{
     foreach ($mailbox in $ou)
      {
          Get-MailBox -ResultSize Unlimited
       }
}

Sorry my powershell isnt all that, still learning it too :)
0
Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
You could simply run the command get-mailbox -Resultsize unlimited and it will check for mailboxes on the domain.
0
SubsunCommented:
Try something like the following example..

@(
"domain/Students/Students-junior/test"
"domain/Students/Students-junior/test1"
"domain/Students/Students-junior/test2"
"domain/Students/Students-junior/test3"
) | % {
Get-MailBox -ResultSize Unlimited  -OrganizationalUnit $_
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SubsunCommented:
Just wondering about the reason for B grade!

Please see the EE guidelines on grading..
http://support.experts-exchange.com/customer/portal/articles/481419
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.