1

I've been creating mailboxes for some of our existing users who don't have their own mailbox so I've written a little script to make things easier for myself. Relevant extract below.

$exchange = New-PSSession -ConfigurationName microsoft.exchange -ConnectionUri http://exchangesvr/powershell
$newMailbox = Invoke-Command -Session $exchange -ScriptBlock{param ($mailbox,$alias)Enable-Mailbox -Identity $mailbox -Database "userdb" -Alias $alias} -ArgumentList $user, $first_last
$mailMessageParameters = @{
            From       = "helpdesk@company"
            To         = $email_address
            Subject    = "Welcome to your new Mailbox!"
            SmtpServer = "exchangesvr" 
            Body       = $emailBody
        }
Send-MailMessage @mailMessageParameters -BodyAsHtml

Trouble with this though is half the time I get a bounceback when sending the mail - I'm assuming the issue is the lookup for the address is happening on a different server in our exchange cluster where the mailbox hasn't replicated to yet. I've tried specifying both a cas server and a hub transport for the creation/mailing, but it doesn't seem to make a difference. I was going to just add a static sleep before sending the mail but I was hoping there is a 'smarter' way of doing this.

JMP
  • 123
  • 1
  • 1
  • 6
  • The GAL is where ? As the replication need to talk to the ad server holding it. Can I ask why you send a email right away ? – yagmoth555 Feb 25 '16 at 03:18
  • Ah, I think that might put me on the right track - if the recipient must be replicated to the GAL first then at least that gives me something I can query. The email is just some customised instructions for the user - there's any particular need to send it immediately - I just want to know why I can't. – JMP Feb 25 '16 at 04:11
  • You may simply give it a little time by inserting a short sleep – Daniel Nachtrub Feb 25 '16 at 07:47

1 Answers1

0

Perhaps the Get-Mailbox cmdlet would be of use?

https://technet.microsoft.com/en-us/library/bb123685(v=exchg.160).aspx

You'd still have to add a wait / re-try block, but at least you would be confident the mail would get there!

sippybear
  • 3,197
  • 1
  • 13
  • 12
  • I'm not certain it is - even if the mailbox can be found with get-mailbox (and if I query the same exchange server I created it on that should be the case) I don't think that guarantees that exchange will find it when it tries to look up the address to deliver the mail. I think yagmoth's comment might be more on point. – JMP Feb 25 '16 at 04:15
  • Get-Mailbox -Server && Send-MailMessage -SmtpServer is insufficient? rats! sorry :( It's interesting that Get-Mailbox | Where {$_.HiddenFromAddressListsEnabled -eq $True} is used to find accounts hidden in from the GAL – sippybear Feb 25 '16 at 04:26