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)