0 votes

Good Morning,

I was hoping to get some assistance in creating a powershell script that I could run daily that would do the following.

1. Gather a list of all AD users with the "Description" of Manager or Supervisor (or any other titles I choose)
2. Populate the "Manager" field in a property pattern with found users

Any assistance would be great.


by (520 points)

1 Answer

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


Have a look at the following script from our repository: https://www.adaxes.com/script-repositor ... h-s516.htm.


That was exactly what I needed!



So I ended up getting this to work, but I came across a small issue.

We have quite a few manager/supervisors that are in this list. The drop down in the "Create Users" form does not list these users in any sort of order. This makes scrolling through trying to find the specific user incredibly difficult.

Any ideas what I could change?




We have updated the script to meet your needs, Find it below.

# Search settings
$propertyForList = "distinguishedName" # TOOD: modify me
$propertyForSearch = "description" # TOOD: modify me
$valuesForSearch = @("Value1", "Value2") # TOOD: modify me
$sortBy = "name" # TODO: modify me
$sortDirection = "Ascending" # TODO: modify me. Possible values: Ascending, Descending

# Property Pattern settings
$patternName = "User Pattern" # TODO: modify me
$propertyToUpdate = "manager" # TODO: modify me
$isPropertyRequired = $True # TODO: modify me

function SearchObjects($filter, $properties, $baseObjectPath, $virtualRoot, $sortBy, $sortDirection)
    $searcher = $Context.BindToObject($baseObjectPath)
    $searcher.SearchFilter = $filter
    $searcher.SearchScope = "ADS_SCOPE_SUBTREE"
    $searcher.PageSize = 500
    $searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
    $searcher.VirtualRoot = $virtualRoot
    if ($sortBy -ne $NULL)
        $sortOption = New-Object "Softerra.Adaxes.Adsi.AdmSortOption"
        $sortOption.PropertyName = $sortBy
        $sortOption.Direction = $sortDirection
        $searcher.Sort = $sortOption

        $searchResultIterator = $searcher.ExecuteSearch()
        $searchResults = $searchResultIterator.FetchAll()

        return ,$searchResults
        # Release resources
        if ($searchResultIterator){ $searchResultIterator.Dispose() }

# Search Property Pattern
$propertyPatternsPath = $Context.GetWellKnownContainerPath("PropertyPatterns")

$searchResults = SearchObjects "(&(objectClass=adm-PropertyPattern)(name=$patternName))" @() $propertyPatternsPath $False $NULL $NULL
if ($searchResults.Length -eq 0)
    $Context.LogMessage("Property Pattern '$patternName' not found.", "Warning")
elseif ($searchResults.Length -gt 1)
    $Context.LogMessage("Found more than one Property Pattern with the following name: '$patternName'.", "Warning")
$propertyPatternPath = $searchResults[0].AdsPath

# Build search filter for users
$filter = New-Object "System.Text.StringBuilder"
$filter.Append([Softerra.Adaxes.Ldap.FilterBuilder]::CreateOrred($propertyForSearch, [System.String[]]$valuesForSearch))

# Search users
$searchResults = SearchObjects $filter.ToString() @($propertyForList) "Adaxes://RootDSE" $True $sortBy $sortDirection

$values = New-Object "System.Collections.ArrayList"
foreach ($searchResult in $searchResults)

# Update Property Pattern
$pattern = $Context.BindToObject($propertyPatternPath)

foreach ($item in $pattern.Items)
    if ($item.PropertyName -ieq $propertyToUpdate)

if ($values.Count -eq 0)

# Create a new item
$item = $pattern.Items.Create()
$item.PropertyName = $propertyToUpdate
$item.IsPropertyRequired = $isPropertyRequired

$constraints = $item.GetConstraints()
$constraint = $constraints.Create("ADM_PROPERTYCONSTRAINTTYPE_VALUERANGE")
$constraint.AreValuesDenied = $False
$constraint.Values = $values.ToArray()

# Save the changes

Worked perfectly, thanks for the help!

Related questions

0 votes
1 answer

We are using the dynamic dist list script found below. The issue is we also have to be able to provide overrides, which we are achieving through secondary static ... ADS_PROPERTY_UPDATE", "member", $userDNs) } # Save the changes $Context.TargetObject.SetInfo()

asked Jun 6, 2018 by willy-wally (3.2k points)
0 votes
1 answer

How do I go about getting an export of users that are assigned to a particular dynamic group? The existing export rules don't seem to do the trick. It only pulls info ... the dynamic group, i would like to also report on those that have been licensed for O365

asked Mar 20, 2017 by cubedit (50 points)
0 votes
0 answers

Hello. Is there a way to get a drop down list with custom and dynamic content in Adaxes administration console (or web)? 1. Get list of available number in dailplan from a ... or disable for Lync' from a temp variable populated in #2. How can we address #2?

asked Sep 27, 2016 by Klas (460 points)
0 votes
1 answer

Hi! I want to auto populate the Manager dropdown list (when HR is creating a new user) with the members of two different groups in our AD. Can this be done? Best regards, Kaj Lehtinen

asked Sep 7, 2017 by KajLehtinen (650 points)
0 votes
1 answer

In the Reports section, there is an option to view "All Users" and then export the view. There is also an option to include additional columns. If I include "Manager", ... along with the complete AD path gets exported. Is it possible to export only the name?

asked Jan 14, 2014 by sdavidson (730 points)
2,737 questions
2,471 answers
1,351,058 users