Hello,
Yes, this is possible. For example, if your SQL database engine has some sort of an API that can be accessed from PowerShell, you can create a PowerShell script that will read possible values from an SQL database. A good example of a database engine that can be accessed from PowerShell is MS SQL.
Then, the script can update Property Patterns based on the values retrieved from the SQL database. Take a look at the following sample in our SDK that demonstrates how to update a list of possible values for the Department property in the built-in User Pattern using Adaxes ADSI API: http://www.adaxes.com/sdk/?SampleScript ... terns.html.
Finally, you can even use the script in Business Rules, Custom Commands or Scheduled Tasks to update the Property Pattern automatically. For example, you can create a Business Rule executed before creating a new user that will automatically update the User Pattern.
Also, take a look at the following script sample. It connects to an MS SQL database specified by $databaseName located on $databaseHost using the credentials of Adaxes default administrator (the user that was specified during Adaxes installation). Then, it loads a list of possible values for the Office property from the field called ADOfficeName in the database table called Offices. After that, it updates the list of possible values of the Office property in the built-in User Pattern. The sample script can be used in Business Rules, Custom Commands or Scheduled Tasks.
$databaseHost = "host.company.com" #TODO: modify me
$databaseName = "MyDatabase" # TODO: modify me
$isOfficePropertyRequired = $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 ADOfficeName FROM Offices"
$reader = $command.ExecuteReader()
$officesName = @()
while ($reader.Read())
{
$officesName += $reader["ADOfficeName"]
}
$reader.Close()
$command.Dispose()
$connection.Close()
if($officesName.Length -eq 0)
{
return
}
# Sort office names in the array
[System.Array]::Sort($officesName)
# Modify the User Pattern
$propertyPatternsPath = $Context.GetWellKnownContainerPath("PropertyPatterns")
$propertyPatternsPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" $propertyPatternsPath
$builtinPathObj = $propertyPatternsPathObj.CreateChildPath("CN=Builtin")
$userPatternPath = $builtinPathObj.CreateChildPath("CN=User Pattern")
$userPattern = $Context.BindToObject($userPatternPath)
foreach ($item in $userPattern.Items)
{
if($item.PropertyName -eq "physicalDeliveryOfficeName")
{
$userPattern.Items.Remove($item)
break
}
}
$item = $userPattern.Items.Create()
$item.PropertyName = "physicalDeliveryOfficeName"
$item.IsPropertyRequired = $isOfficePropertyRequired
$constraints = $item.GetConstraints()
$constraint = $constraints.Create("ADM_PROPERTYCONSTRAINTTYPE_VALUERANGE")
$constraint.AreValuesDenied = $False
$constraint.Values = $officesName
$constraints.Add($constraint)
$item.SetConstraints($constraints)
$item.SetInfo()
$userPattern.Items.Add($item)
If you need any assistance with the script, we can help you or even write it for you.