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:
Write-output “ENTER THE FOLLOWING DETAILS”
$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 <[email protected]>" -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`[email protected]" -SmtpServer genericexchange.exchange.com
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.
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):
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: http://social.technet.microsoft.com/Forums/en/ITCG/thread/499deabf-a12d-470a-8773-b11ffa9c8694
Thanks again Karl!!!
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?