I'm using the following script to modify newly-created linked-mailbox users'' SMTP addresses (Thanks to the community for helping me with this):
function onPostCreate($Request)
{
$First = $Request.Get("givenName")
$Last = $Request.Get("sn")
$Primary = $First + "." + $Last + "@mydomain.com"
$Local = $First + "." + $Last + "@anotherdomain.local"
Get-QADUser $Request.dn | Add-QADProxyAddress -Type SMTP -Address $primary -PRIMARY
Get-QADUser $Request.dn | Add-QADProxyAddress -Type SMTP -Address $Local
Get-QADUser $Request.dn | Remove-QADProxyAddress -Pattern '*@myolddomain.com'
}
It works great when creating a new user and then a linked mailbox. However, we've discovered that several users are being created in a different OU which the policy does not affect. We have been moving the users to the appropriate OU and creating the linked mailbox. But, the script is not firing on these users. My theory is since these are not newly created users, OnPostCreate isn't going to work.
So, I created an identical script but set the function to OnPostMove. If I link the user's mailbox and then move that user to the "good" OU, the Quest script will fire but it will fail with the following error:
ERROR:
At line: 9 char:52. Administrative Policy returned an error.
The specified e-mail address 'SMTP:.@mydomain.com' already exists in this organization.
So it looks like it isn't processing the variables in the way that I had expected, and attempting to give the user an SMTP address of ".@mydomain.com". I'm guessing that the $Request variable in ActiveRoles is different on a move vs. a create? Is this the case, and any pointers on how to fix this? Thanks in advance.