Hello,
To achieve what you want, you'll need to create a Home Page Action. The Home Page Action will modify a certain attribute of an initiator's account and will set it to the name of the user who needs to be put back to managed. For this purpose, you can use an Adaxes virtual property that can store string (text) values, for example, CustomAttributeText1. Such properties are not stored in Active Directory, but can be used the same as any other properties of AD objects. A Business Rule triggered when the attribute is modified will find the necessary unmanaged account and remove it from the unmanaged list.
Also, in order to show a list of all unmanaged accounts, you'll need a script that will create a Property Pattern item for the property that you want to use (e.g. Custom AttributeText1) and will impose the 'must be one of the following values only' type of constraint on the property, where the allowed values will be the names of the unmanaged accounts. Thus, when editing the selected property, users will see a drop-down list of all currently unmanaged accounts.
To use the script with Adaxes, you'll need to create a Scheduled Task. The task will use the script to update the list of unmanaged accounts in the Property Pattern on a periodical basis. Also, you've mentioned that you have a script that updates the Unmanaged Accounts in your environment. If the script is also run by a Scheduled Task, Instead of creating a separate Scheduled Task, you can simply add the below script to your existing Scheduled Task, placing it after the script that updates Unmanaged Accounts so that the Property Pattern would be updated right after your current script updates the Unmanaged Accounts.
The Script:
$propertyForUserList = "adm-CustomAttributeText1" # TODO: modify me
$configurationSetSettingsPath = $Context.GetWellKnownContainerPath("ConfigurationSetSettings")
$admConfigurationSetSettings = $Context.BindToObject($configurationSetSettingsPath)
# Get all unmanaged accounts
$currentUnmanagedAccounts = $admConfigurationSetSettings.GetUnmanagedAccounts(@("cn", "userPrincipalName"))
$values = @()
foreach ($userInfo in $currentUnmanagedAccounts)
{
$searchResult = $userInfo.Value
if ($searchResult -eq $NULL)
{
continue
}
$userPrincipalName = $searchResult.Properties["userPrincipalName"].Value
$fullName = $searchResult.Properties["cn"].Value
$values += "$fullName ($userPrincipalName)"
}
# Update 'User Pattern'
# Bind to '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")
$pattern = $Context.BindToObject($userPatternPath)
# Delete the item for the specified property
foreach ($item in $pattern.Items)
{
if ($item.PropertyName -ieq $propertyForUserList)
{
$pattern.Items.Remove($item)
break
}
}
# Add unmanaged accounts to the Property Pattern
$item = $pattern.Items.Create()
$item.PropertyName = $propertyForUserList
$constraints = $item.GetConstraints()
$constraint = $constraints.Create(
"ADM_PROPERTYCONSTRAINTTYPE_VALUERANGE")
$constraint.AreValuesDenied = $False
$constraint.Values = $values
$constraints.Add($constraint)
$item.SetConstraints($constraints)
$item.SetInfo()
$pattern.Items.Add($item)
The script updates the built-in User Pattern that is applied to all users by default. In the script, $propertyForUserList specifies the property that will be used for the name of the user removed from Unmanaged Accounts.
To create a separate Scheduled Task:
- Create a new Scheduled Task.
- On the 3rd step of the Create Scheduled Task wizard, select Show all object types and select the Domain-DNS object type. Running a task on a domain allows you to run the script only once per a task run.
- On the 4th step, add the Run a program or PowerShell script action and paste the above script in the Script field.
- On the 5th step, include any of your AD domains in the Activity Scope of the task.
For information on how to create a Home Page Action that will allow users to specify an account in Adaxes Web interface, see section Modify Object in the Configure Home Page Actions Tutorial. Use it as a guide.
- Since initiators will modify their own accounts to specify a user to be removed from Unmanaged Accoutns, on Step 3 of the section, you need to configure the Home Page Action to always modufy the initiator's account. For this purpose, select the Always perform for the current user option.
- On Step 4, you wll find instructions on how to modify the form used by the action. Modify the form so that it would show only the property that will be used to specify the Unmanaged Account, e.g. CustomAttributeText1.
To create a Business Rule that will remove a user specified from unmanaged accounts:
-
Create a new Business Rule.
-
On the 2nd step of the Create Business Rule wizard, select User and After Updating a User.
-
On the 3rd step, add the Run a program or PowerShell script action and paste the following script in the Script field.
$propertyForUserList = "adm-CustomAttributeText1" # TODO: modify me
# Search selected user in unmanaged accounts
$configurationSetSettingsPath = $Context.GetWellKnownContainerPath("ConfigurationSetSettings")
$admConfigurationSetSettings = $Context.BindToObject($configurationSetSettingsPath)
# Get all unmanaged accounts
$currentUnmanagedAccounts = $admConfigurationSetSettings.GetUnmanagedAccounts(@("cn", "userPrincipalName"))
$allUnmanagedSids = New-Object "System.Collections.Generic.HashSet[String]"
$userIndentity = $Context.TargetObject.Get($propertyForUserList)
$userFullName = $userIndentity.SubString(0, $userIndentity.IndexOf("(") - 1)
$userPrincipalName = $userIndentity.SubString($userIndentity.IndexOf("(") + 1, $userIndentity.IndexOf(")") - $userIndentity.IndexOf("(") - 1)
$updateUnmanagedAccounts = $False
foreach ($userInfo in $currentUnmanagedAccounts)
{
$searchResult = $userInfo.Value
if ($searchResult -eq $NULL)
{
continue
}
$principalName = $searchResult.Properties["userPrincipalName"].Value
$fullName = $searchResult.Properties["cn"].Value
if (($principalName -ieq $userPrincipalName) -and ($fullName -ieq $userFullName))
{
$updateUnmanagedAccounts = $True
continue
}
$allUnmanagedSids.Add($userInfo.Key) | Out-Null
}
if ($updateUnmanagedAccounts)
{
# Update unmanaged accounts
$admConfigurationSetSettings.SetUnmanagedAccounts(@($allUnmanagedSids))
# Clear custom attribute
$Context.TargetObject.Put($propertyForUserList, $NULL)
$Context.TargetObject.SetInfo()
}
else
{
$Context.LogMessage("User with indentity '$userIndentity' was not found in the Unmanaged Accounts", "Warning")
}
-
In the script, $propertyForUserList specifies the property that will be used for the name of the user removed from Unmanaged Accounts. Modify it, if necessary.
-
Enter a short description for the script and click OK.
-
Now, you need to add a condition when the script will be executed. Right-click the action that you've just added and select Add Condition.
-
Select the If <property> <changed> condition type.
-
In the <property> drop-down list, select Show all properties and select the virtual attribute that you chose, e.g. CustomAttributeText1.
-
Select has changed.
-
Click OK.
-
Also, the script to must be launched only when an account is specified, that is, when the virtual attribute is not empty. Right-click the action that you've added and select Add Condition again.
-
Select the If <property> <relation> <value> condition type.
-
In the <property> drop-down list, select Show all properties and select the virtual property that you chose, e.g. CustomAttributeText1.
-
Select is not empty.
-
Click OK.
-
Finish creation of the Business Rule.
Since a name like CustomAttributeText1 will not tell much to your users about the function of the property, you can also configure Adaxes to specify a different display name for the property.