0 votes

Hello Support,

Now that I have tested the code below that you created for me I need to reset the $initialnumber in the global configuration.
Where can I reset that? Do I need some more code to run as a one off to reset the 888222 number?

$usernameFormat = "A{0:000000}" # TODO: modify me
$initialNumber = 888222 # TODO: modify me
$maxNumber = 900000 # TODO: modify me

$settingsPath = $Context.GetWellKnownContainerPath("ConfigurationSetSettings")
$settings = $Context.BindToObject($settingsPath)

# Get the next contractor number from global configuration
try
{
    $number = [int]($settings.Get("adm-CustomAttributeInt1"))
    $number++
}
catch
{
    # If no number is set in the global configuration, use the initial number
    $number = $initialNumber
}

$uniqueUsername = [System.String]::Format($usernameFormat, $number)
do
{
    if ($number -gt [int]$maxNumber)
    {
        $Context.Cancel("Cannot generate a username for the contractor because the maximum allowed contractor number has been reached. Please contact your system administrator.")
        return
    }

    # Check whether the username is unique
    $searcher = $Context.BindToObject("Adaxes://rootDse")
    $searcher.PageSize = 500
    $searcher.SearchScope = "ADS_SCOPE_SUBTREE"
    $searcher.SearchFilter = "(&(sAMAccountType=805306368)(sAMAccountName=$uniqueUsername))"
    $searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
    $searcher.VirtualRoot = $True

    try
    {
        $searchResult = $searcher.ExecuteSearch()
        $result = $searchResult.FetchAll()

        # If the username is not unique, find a unique one
        if ($result.Count -ne 0)
        {
            $number++
            $uniqueUsername = [System.String]::Format($usernameFomrat, $number)
        }
    }
    finally
    {
        $searchResult.Dispose()
    }

}
while ($result.Count -ne 0)

# Save the new number in the gloabal settings
$settings.Put("adm-CustomAttributeInt1", $number)
$settings.SetInfo()
by (840 points)
0

Guys,

I took another look at this earlier and sorted something out, thanks anyway.

John.

0

Hello Support,

Now that I have tested the code below that you created for me I need to reset the $initialnumber in the global configuration.
Where can I reset that? Do I need some more code to run as a one off to reset the 888222 number?

$usernameFormat = "A{0:000000}" # TODO: modify me
$initialNumber = 888222 # TODO: modify me
$maxNumber = 900000 # TODO: modify me

$settingsPath = $Context.GetWellKnownContainerPath("ConfigurationSetSettings")
$settings = $Context.BindToObject($settingsPath)

# Get the next contractor number from global configuration
try
{
    $number = [int]($settings.Get("adm-CustomAttributeInt1"))
    $number++
}
catch
{
    # If no number is set in the global configuration, use the initial number
    $number = $initialNumber
}

$uniqueUsername = [System.String]::Format($usernameFormat, $number)
do
{
    if ($number -gt [int]$maxNumber)
    {
        $Context.Cancel("Cannot generate a username for the contractor because the maximum allowed contractor number has been reached. Please contact your system administrator.")
        return
    }

    # Check whether the username is unique
    $searcher = $Context.BindToObject("Adaxes://rootDse")
    $searcher.PageSize = 500
    $searcher.SearchScope = "ADS_SCOPE_SUBTREE"
    $searcher.SearchFilter = "(&(sAMAccountType=805306368)(sAMAccountName=$uniqueUsername))"
    $searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
    $searcher.VirtualRoot = $True

    try
    {
        $searchResult = $searcher.ExecuteSearch()
        $result = $searchResult.FetchAll()

        # If the username is not unique, find a unique one
        if ($result.Count -ne 0)
        {
            $number++
            $uniqueUsername = [System.String]::Format($usernameFomrat, $number)
        }
    }
    finally
    {
        $searchResult.Dispose()
    }

}
while ($result.Count -ne 0)

# Save the new number in the gloabal settings
$settings.Put("adm-CustomAttributeInt1", $number)
$settings.SetInfo()

1 Answer

0 votes
by (216k points)
selected by
Best answer

Hello,

To reset the number in the global configuration, you can create an action for the Web Interface that allows you to input the initial number you want to set. The value from the action will be assigned to one of Adaxes virtual attributes of the user who launches the action. Such virtual attributes that are not stored in Active Directory, but you can use them in Adaxes the same as any regular attribute of AD objects. Also, you can create a Business Rule that will be triggered when the virtual attribute is modified to launch a PowerShell script. The script will update the number in the global configuration setting to the value that you specify.

For information on how to implement such a solution, see the following post on this support forum: Custom Command That Does Not Execute on Object. The initial number that will be set in the global configuration will be passed via the CustomAttributeInt1 virtual attribute, which you will need to add to the form used by the action. On step II.3 of the post, you need to use the following script:

$number = $Context.TargetObject.Get("adm-CustomAttributeInt1")

$settingsPath = $Context.GetWellKnownContainerPath("ConfigurationSetSettings")
$settings = $Context.BindToObject($settingsPath)

# Save the new number in the gloabal settings
$settings.Put("adm-CustomAttributeInt1", $number)
$settings.SetInfo()

# Clear custom attribute from user
$Context.TargetObject.Put("adm-CustomAttributeInt1", $NULL)
$Context.TargetObject.SetInfo()

Related questions

0 votes
1 answer

Hello! We are using the current version of Adaxes and are in the process of making the password self-service available to our users. We have installed the self-service client ... are doing wrong? Thanks Erik [EDIT]: Corrected image links. Sorry about that...

asked Jun 6, 2014 by eventit (160 points)
0 votes
1 answer

I added the Password last set field to the Admin view but when I click on edit it allows the admin user to change the value. Adaxes correclty handel Bad Password time and Bad password ... last set, so I guest there is a way but I can not find it. Thanks you

asked Dec 19, 2019 by tomlaf (60 points)
0 votes
1 answer

It appears that we can allow conflicting meetings on a room mailbox but can't set the number of allowed conflicts. Is this a bug or intended? Can we request this feature? Do ... to create a custom command for this? We are on version 3.14.19723.0 Thanks, Mark

asked Jul 13, 2022 by mark.it.admin (2.3k points)
0 votes
1 answer

Hi, I already have a home page action to add a user to a security group but the security group owners want some info on the user requesting access to the group because ... get some sort of "more info" box asking for details before any approval steps? Thanks.

asked Feb 4, 2016 by bistromath (840 points)
0 votes
1 answer

EDIT: Actually, it would be better if I could just add the ownerDN to the groups automatically regardless of the initiator! Would that make it easier? Hi All, I have ... for approval for users being added to groups, can this request bypass that? Thanks John.

asked Sep 29, 2015 by bistromath (840 points)
3,347 questions
3,048 answers
7,788 comments
545,040 users