This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

MAIL ADDRESS GENERATION POLICY WITH DUPLICATE CHECKING

Is is possible to generate unique mail address based on policy ?

policy should use incremental number in case of duplicate.

Parents
  • You're going to have to implement this with a script policy that you fire using an OnPreCreate Handler.

    Something like this:

    Function OnPreCreate ($Request)
    {

    # <implement some code to acquire stored credentials for Exchange> and assign to "$UserCredential">

    # Load Exchange cmdlets

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<FQDN of Exchange server>/PowerShell/ -Authentication Kerberos -Credential $UserCredential
    Import-PSSession $Session

    # Implement whatever formula you like for your e-mail address
    # Sample below first.last@domain.com

    $ProposedEmail = $Request.get("firstname") + "." + $Request.get("sn") + "@domain.com"

    $GoodEmail = $False

    While ($GoodEmail -eq $false)
    {
    # See if our proposed address is in use anywhere in Exchange
    $EmailCheck = Get-Recipient $ProposedEmailAddress

    If ($EmailCheck -eq $null)
    {
    # If we get nothing back from the Get-Recipient, set our good flag and ignore the
    # the rest of the code in the loop
    $GoodEmail = $true
    continue
    }

    # Calculate the numeric suffix

    $NumericSuffix += 1

    $NumericSuffixString = $NumericSuffix.tostring()

    # Rebuild the email address with the suffix

    $ProposedEmail = $Request.get("firstname") + "." + $Request.get("sn") + $NumericSuffixString + "@domain.com"


    } # End of While loop

    # Add the new email into the create transaction (i.e. ActiveRoles Request object)
    $Request.Put("targetaddress",$ProposedEmail)

    # Kill the PoSh Session with Exchange

    Get-PSSession | Remove-PSSession

    } # End of Handler
Reply
  • You're going to have to implement this with a script policy that you fire using an OnPreCreate Handler.

    Something like this:

    Function OnPreCreate ($Request)
    {

    # <implement some code to acquire stored credentials for Exchange> and assign to "$UserCredential">

    # Load Exchange cmdlets

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<FQDN of Exchange server>/PowerShell/ -Authentication Kerberos -Credential $UserCredential
    Import-PSSession $Session

    # Implement whatever formula you like for your e-mail address
    # Sample below first.last@domain.com

    $ProposedEmail = $Request.get("firstname") + "." + $Request.get("sn") + "@domain.com"

    $GoodEmail = $False

    While ($GoodEmail -eq $false)
    {
    # See if our proposed address is in use anywhere in Exchange
    $EmailCheck = Get-Recipient $ProposedEmailAddress

    If ($EmailCheck -eq $null)
    {
    # If we get nothing back from the Get-Recipient, set our good flag and ignore the
    # the rest of the code in the loop
    $GoodEmail = $true
    continue
    }

    # Calculate the numeric suffix

    $NumericSuffix += 1

    $NumericSuffixString = $NumericSuffix.tostring()

    # Rebuild the email address with the suffix

    $ProposedEmail = $Request.get("firstname") + "." + $Request.get("sn") + $NumericSuffixString + "@domain.com"


    } # End of While loop

    # Add the new email into the create transaction (i.e. ActiveRoles Request object)
    $Request.Put("targetaddress",$ProposedEmail)

    # Kill the PoSh Session with Exchange

    Get-PSSession | Remove-PSSession

    } # End of Handler
Children
No Data