Powershell calculate number between 1 and 50 to use variable exchange databases

Posted on 2013-05-20
Last Modified: 2013-05-31

i like to enable mbx of a lot of user from a CSV but i want to use different databases between
DB0001 and DB0050. How can i create this to use with following cmd-

Enable-Mailbox -Identity $User.UserID -Database DB0001

appreciate for your help
Question by:Mandy_
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 40

Assisted Solution

Subsun earned 250 total points
ID: 39180234
If you are looking for random numbers then try with Get-random
Enable-Mailbox -Identity $User.UserID -Database "DB00$("{0:00}" -f (1..50 | Get-random))"

Open in new window

LVL 42

Accepted Solution

sedgwick earned 250 total points
ID: 39180247
gc c:\temp\users.csv | %{
$db =  "DB00$("{0:00}" -f (1..50 | Get-random))"
Enable-Mailbox -Identity $_ -Database $db

Open in new window

LVL 12

Expert Comment

ID: 39180628
Incidentally, if you don't specify a database when creating a mailbox,
exchange will load balance the mailboxes across all available databases automatically.

Depending on your setup, this may be redundant code.
LVL 40

Expert Comment

ID: 39194491
@Mandy_, May I ask you the reason you selected Sedgwick's commend as answer? In fact, I did provide the method to get random numbers. Sedgwick just elaborated it using same method. A split in points would be more fair.. :-)
LVL 42

Expert Comment

ID: 39198167
I agree points should be splited

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
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.
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

729 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