0 votes

Hi,

I adapted the code found in this thread to my needs Import Constraints

The method works and it does create and populate the property pattern, however after running the script when I go to the property pattern section and doubleclick to open the specific one just created I get 'Catastrophic Failure' error message.

    $databaseHost = "OURSQLSERVER" 
    $databaseName = "Adaxes_data" 
    $isRolePropertyRequired = $True

    # Use the credentials of the default Adaxes administrator
    # to connect to the database.
    $databaseUsername = $NULL
    $databasePassword = $NULL

    # Get the office name
    $connectionString = "Data Source=$databaseHost; Initial Catalog=$databaseName;"
    if ($databaseUsername -eq $NULL)
    {
        $connectionString = $connectionString +
            "Integrated Security=SSPI;"
    }
    else
    {
        $connectionString = $connectionString +
            "User ID=$databaseUsername;Password=$databasePassword;"
    }

    $connection = New-Object "System.Data.SqlClient.SqlConnection"  $connectionString
    $connection.Open()

    $command = $connection.CreateCommand()
    $command.CommandText = "SELECT DISTINCT role FROM dbo.teammemberlist"

    $reader = $command.ExecuteReader()

    $rolesName = @()
    while ($reader.Read())
    {
        $rolesName += $reader["role"]
    }

    $reader.Close()
    $command.Dispose()
    $connection.Close()

    if($rolesName.Length -eq 0)
    {
                return
    }

    # Sort office names in the array
    [System.Array]::Sort($rolesName)

    # Modify the User Pattern
    $propertyPatternsPath = $Context.GetWellKnownContainerPath("PropertyPatterns")
    $propertyPatternsPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" $propertyPatternsPath
    $builtinPathObj = $propertyPatternsPathObj.CreateChildPath("CN=Applied")
    $userPatternPath = $builtinPathObj.CreateChildPath("CN=User Pattern")

    $userPattern = $Context.BindToObject($userPatternPath)

    foreach ($item in $userPattern.Items)
    {
        if($item.PropertyName -eq "CustomAttributeText2")
        {
            $userPattern.Items.Remove($item)
            break
        }
    }

    $item = $userPattern.Items.Create()
    $item.PropertyName = "CustomAttributeText2"
    $item.IsPropertyRequired = $isRolePropertyRequired

    $constraints = $item.GetConstraints()
    $constraint = $constraints.Create("ADM_PROPERTYCONSTRAINTTYPE_VALUERANGE")
    $constraint.AreValuesDenied = $False
    $constraint.Values = $rolesName
    $constraints.Add($constraint)
    $item.SetConstraints($constraints)

    $item.SetInfo()
    $userPattern.Items.Add($item)
by (240 points)

1 Answer

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

Hello,

The error occurs because you are using the attribute display name, but you need to use the LDAP name instead. To remedy the issue, find all occurrences of CustomAttributeText2 in your script and replace them with adm-CustomAttributeText2.

0

That did the trick, thanks!

Related questions

0 votes
1 answer

We have a form to used by our HR Reps to create non-employee records. There are two fields on the form that are auto-generated via a property pattern: Full Name ( ... changed to cause this new behavior? Nothing has changed with our property pattern set-up...

asked Aug 30, 2016 by sandramnc (870 points)
0 votes
1 answer

Is there an option to load the possibles values of the Property Pattern, from SQL or other external sources?

asked Aug 5, 2013 by sdavidson (730 points)
0 votes
1 answer

Hi All, I am currently using the 30 day free trial of Adaxes and seeing if we can use it to achieve our method of user provisioning. I am looking into server-side ... variable value within an SQL query Can this be achieved? Any help is much appreciated, Thanks

asked Feb 1 by Lewis (40 points)
0 votes
1 answer

Dear colleagues, can you please advise if it is possible to create (and update reqularly) business unit of computer objects based on a query to external SQL DB (hostnames stored in SQL)? Thanks!

asked Dec 14, 2022 by Dmytro.Rudyi (920 points)
0 votes
0 answers

Is it possible to query the external SQL database for audits of a specific action, even if that action is a 'sub-command' of a business rule, scheduled task etc? Simple ... interested if data is structured in the log in a manner that would allow this? Thanks

asked Aug 30, 2014 by firegoblin (1.6k points)
3,588 questions
3,277 answers
8,303 comments
548,090 users