0

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
1
  • If anyone wants to see the completed script let me know and I'll post it up when it's done.
    – Paul Masek
    Mar 9, 2011 at 20:19

3 Answers 3

1

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)
2
  • 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.EnableMailbox
    – Paul Masek
    Mar 9, 2011 at 20:06
  • This was the result of trying that line. Thank you for trying though Shane!
    – Paul Masek
    Mar 9, 2011 at 20:08
1

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!!!

0
Write-output “ENTER THE FOLLOWING DETAILS”
$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 <[email protected]>" -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`[email protected]" -SmtpServer GenericCo.Generic.com

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .