0 votes

This will run in a business rule "after creating a user" The email should be set to %firstname:lower%%lastname:lower%@mydomain. If the email isn't unique then it shoud be set to %firstname:lower%%initials:lower%%lastname:lower%@mydomain and if that isn't unique fail and log the failure. This should update the emailaddress attribute in AD(not updating anything in Azure).

by (1.0k points)
0

Hello,

What exactly do you mean by if that isn't unique fail? Should user creation be cancelled in this case?

0

Since it the business rule would run after the user is created the user creation wouldn't fail just the script would log that it couldn't create a unique email account.

0

Hello,

Thank you for clarifying. For us to help you with the script, please, specify the version of Adaxes you are currently using. For information on how to check it, have a look at the following help article: https://www.adaxes.com/help/CheckServiceVersion.

0

image.png

1 Answer

+1 vote
by (272k points)

Hello,

Thank you for specifying. You can use the below script:

$initialEmailTemplate = "%firstname:lower%%lastname:lower%@mydomain.com" # TODO: modify me
$secondaryEmailTemplate = "%firstname:lower%%initials:lower%%lastname:lower%@mydomain.com" # TODO: modify me

function CheckEmailUniqueness ($mail)
{
    # Build search criteria
    $criteria = New-AdmCriteria "user" {mail -eq $mail}

    # Search for users with the username or email address specified
    $searcher = $Context.TargetObject
    $searcher.Criteria = $criteria
    $searcher.VirtualRoot = $True
    $searcher.SizeLimit = 1

    try
    {
        $searchResultIterator = $searcher.ExecuteSearch()
        $searchResults = $searchResultIterator.FetchAll()

        return $searchResults.Length -eq 0
    }
    finally
    {
        # Release resources
        $searchResultIterator.Dispose()
    }
}

function UpdateUser ($mail)
{
    # Update the user
    $Context.TargetObject.Put("mail", $mail)
    $Context.TargetObject.SetInfo()
}

# Check first temaplte for uniqueness
if (CheckEmailUniqueness $initialEmailTemplate)
{
    UpdateUser $initialEmailTemplate
    $Context.LogMessage("$initialEmailTemplate set as user email.", "Information")
    return
}

# Check second temaplte for uniqueness
if (CheckEmailUniqueness $secondaryEmailTemplate)
{
    UpdateUser $secondaryEmailTemplate
    $Context.LogMessage("$secondaryEmailTemplate set as user email.", "Information")
    return
}

$Context.LogMessage("Could not generate a unique email address for user %fullname%.", "Error")
0

Thank you works perfectly.

Related questions

0 votes
1 answer

We're looking at adding a powershell script to check for duplicate Exchange Aliases within our exchange organization prior to a user modification. We've noticed that ... .LogMessage($uniqueUsername + "@domain.com", "Error"); Thanks for your assistance!

asked Aug 14, 2014 by VTPatsFan (610 points)
0 votes
1 answer

Greetings. When I create the parameters to make a business rule that looks for users whose Email Proxy Adresses does not contain 'SMTP:%userPrincipalName%', it still generates profiles ... and primary SMTP address don't match. Version is 2023 How rule is set

asked Dec 19, 2022 by MShep (80 points)
0 votes
1 answer

So this works for us however we would like to add to check if the last group is at 3 users we would like to send a seperate email but would still like all the above to continue to happen the way it is.

asked Mar 2, 2022 by Keonip (160 points)
0 votes
1 answer

We have users with a value of a space for their mobile number and telephone number. I would like to figure out who these users are and null the value. Or if the value contains a number leave it alone. if it does not have a number then null the value.

asked Nov 15, 2022 by B_Witmer (40 points)
0 votes
1 answer

The section is not defined in the available options in Adaxes and it is in the AD as well. Eg; I need to add a section called ' Security Access' and have it ... to select from options like User Directory, Internet access, Track-It account , SAP access etc.

asked Oct 13, 2021 by Aishwarya Gavali (40 points)
3,351 questions
3,052 answers
7,791 comments
545,102 users