The script updates allowed property values in the specified property patterns based on the CSV file. To execute the script, create a scheduled task configured for the Domain object type and add a managed domain to the Activity Scope of the task. The domain will only be used to trigger execution of the scheduled task.
Parameters:
- $propertyPatternDNs - Specifies the distinguished names (DNs) of the property patterns to update. For detials on how to get an object DN, see https://adaxes.com/sdk/HowDoI.GetDnOfObject/.
- $csvFilePath - Specifies the path to the CSV file to import.
- $delimiter - Specifies the separator for columns in CSV file.
- $columnToPropertyNames - Maps CSV column headers with schema names of the corresponding properties.
PowerShell
$propertyPatternDNs = @(
"CN=My Pattern1,CN=Patterns,CN=Property Patterns,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes",
"CN=My Pattern2,CN=Patterns,CN=Property Patterns,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes") # TODO: modify me
$csvFilePath = "C:\Scripts\Addresses.csv" # TODO: modify me
$delimiter = ";" # TODO: modify me
$columnToPropertyNames = @{
"Strasse" = "streetAddress";
"PLZ" = "department";
"Ort" = "l";
} # TODO: modify me
function UpdatePropertyPattern ($pattern, $propertyName, $values)
{
foreach ($item in $pattern.Items)
{
if ($item.PropertyName -ieq $propertyName)
{
$pattern.Items.Remove($item)
break
}
}
if ($NULL -eq $values)
{
return
}
# Create a new item
$item = $pattern.Items.Create()
$item.PropertyName = $propertyName
$item.IsPropertyRequired = $True
$constraints = $item.GetConstraints()
$constraint = $constraints.Create("ADM_PROPERTYCONSTRAINTTYPE_VALUERANGE")
$constraint.AreValuesDenied = $False
$constraint.Values = $values
$constraints.Add($constraint)
$item.SetConstraints($constraints)
# Save the changes
$item.SetInfo()
$pattern.Items.Add($item)
}
function GetValues ($records, $column)
{
$values = New-Object "System.Collections.Generic.HashSet[System.String]"
foreach ($record in $records)
{
$value = $record.$column
if ([System.String]::IsNullOrEmpty($value))
{
continue
}
[Void]$values.Add($value)
}
if ($values.Count -eq 0)
{
return $NULL
}
else
{
return $values
}
}
# Import CSV
$records = Import-Csv -Path $csvFilePath -Delimiter $delimiter
# Get values
$propertyToValue = @{}
foreach ($column in $columnToPropertyNames.Keys)
{
$values = GetValues $records $column
$propertyToValue.Add($columnToPropertyNames[$column], [System.String[]]$values)
}
foreach ($dn in $propertyPatternDNs)
{
$pattern = $Context.BindToObjectByDN($dn)
foreach ($propertyName in $propertyToValue.Keys)
{
UpdatePropertyPattern $pattern $propertyName $propertyToValue[$propertyName]
}
}