Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've scoured the interwebs for a few days now off and on to find this. I am creating a powershell script for email-enabling new user's(Exchange 2007).

To give you a little background when we have a new hire, their AD account is created at our off-site helpdesk, but they don't create their email account.

I'm trying to automate the process of mail-enabling the user which involves putting them in the same database as an existing user, disable imap pop activesync, and lastly email the requester of the ticket.

I would like to just get prompted for the New User's name, User to Replicate(mailbox, storage group, database), and the person to email after it's been created.

So if someone could just help with a command to Retrieve a user's Exchange database in powershell that would be great, but if people also want to help with my hacked up script please do so as well!!!

Here is what I have so far:

$DName = Read-Host “User Diplay Name"
$RUser = Read-Host "Replicate User(Database Grab)"
$RData = #get the Replicate user's mailbox database here
$REmail = #either just use a Read-Host “Requester's Email address" or ask for Requester's name and pipe through their email address by digging for it w/ powershell
Enable-Mailbox -Identity "$DName" -Database "$RData" 
Send-MailMessage -From "John Doe <>" -To (put $REmail here which is the Requester's email) -Subject "Test Person's email account" -Body "Test Person's email account has been setup.`n`n`nJohn Doe`nGeneric Company`nSystems Administrator`nOffice: 123.456.7890`" -SmtpServer
share|improve this question
If anyone wants to see the completed script let me know and I'll post it up when it's done. – Paul Mar 9 '11 at 20:19

This should get you on the right track, the caveat being that you'd need the AD powershell stuff working; this requires at least one 2008R2 DC.

GetADUser -Identity "$RUser" -Properties homeMDB

On a side note, careful with your word-auto-formatted directional quotes - I don't know off the top of my head whether Powershell plays nice with those, but they certainly did a number on StackExchange's code coloring.

I don't envy you trying to do this in powershell - be careful to validate the inputs that are user enterable, and log the results of the commands.

Edit: You know what, that property from AD would probably not be formatted how exchange wants it. Try this instead (and won't need 2008R2):

$RData = (Get-User -Identity "$RUser" | Get-Mailbox | Select-Object Database)
share|improve this answer
Enable-Mailbox : Cannot bind parameter 'Database'. Cannot convert value "@{Database=EXCHANGEMB2\SG5\DB1}" to type "Microsoft.Exchange.Configuration.Tasks.DatabaseIdParamet er". Error: "'@{Database=EXCHANGEMB2\SG5\DB1}' is not a valid value for the identity. Parameter name: Identity" At C:\EmailClientBasic.ps1:9 char:44 + Enable-Mailbox -Identity "$DName" -Database <<<< "$RData" + CategoryInfo : InvalidArgument: (:) [Enable-Mailbox], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Exchange.Management.RecipientTasks.Enab‌​leMailbox – Paul Mar 9 '11 at 20:06
This was the result of trying that line. Thank you for trying though Shane! – Paul Mar 9 '11 at 20:08
up vote 1 down vote accepted

Karl Mitschke over at The Official Scripting Guys Forum! was able to solve my dilemma!

$RData = ((Get-Mailbox -Identity $RUser).Database).DistinguishedName

Here is the link:

Thanks again Karl!!!

share|improve this answer
$DName = Read-Host “User Diplay Name"
$RUser = Read-Host "Replicate User(Database Grab)"
$RData = ((Get-Mailbox -Identity $RUser).Database).DistinguishedName
$REmail = Read-Host “Requester's Email Address"

Enable-Mailbox -Identity "$DName" -Database "$RData" 
Set-CASMailbox -Identity "$DName" -ActiveSyncEnabled $false -ImapEnabled $false -PopEnabled $false

Send-MailMessage -From "John Doe <>" -To $REmail -Subject "$DName's email account" -Body "$DName's email account has been setup.`n`n`nJohn Doe`nGeneric Co.`nSystems Administrator`nOffice: 123.456.7890`" -SmtpServer

This is my near final build. I am trying to just ask for the Requester's name instead of the whole email address and have a powershell command to retrieve it.

This is the closest I have come. Wondering if it isn't handing off the address properly?

$REmailInput = Read-Host “Requester's Name(Notification Email goes to this Person)"
$REmail = Get-Mailbox -Identity "$REmailInput" | Select-Object PrimarySmtpAddress
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.