How do I create a new mailbox and set the properties using Exchange Management Shell?

I have to create a bunch of new users. To make things easier (and a lot faster) I am using a simple batch script.  I am using set to set some enviroment values.(ex. set account=johndoe)

I know how to create a new mailbox using the Exchange Management Shell but is it possible to use/push the enviroment settings (used in the batch script) to the Exchange Management Shell?


The batch file contains the following enviroment settings:

set firstname=John
set surname=Doe
set account=johndoe

These enviroment settings should be used to create the new mailbox in the Exchange Management Shell:

Enable-Mailbox -Identity 'domain.local/Administration/%firstname% %surname%' -Alias '%account%' -Database 'SERVER\First Storage Group\Mailbox Database'

I'm a noob when it comes to powershell/management shell so I would greatly appreciate it if someone could tell me how to achieve this.

Thanks in advance!
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.

Accessing to environment variables in powershell:
[PS] C:\Windows\system32>$env:systemroot

Open in new window


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
My article for creating mailboxes using settings from a CSV may help you here:

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

From novice to tech pro — start learning today.