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.

Thanks!

by (520 points)

1 Answer

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

Hello,

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

0

That was exactly what I needed!

Thanks!

0

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?

Thanks

0

Hello,

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.SetPropertiesToLoad($properties)
    $searcher.VirtualRoot = $virtualRoot
    if ($sortBy -ne $NULL)
    {
        $sortOption = New-Object "Softerra.Adaxes.Adsi.AdmSortOption"
        $sortOption.PropertyName = $sortBy
        $sortOption.Direction = $sortDirection
        $searcher.Sort = $sortOption
    }

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

        return ,$searchResults
    }
    finally
    {
        # 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")
    return
}
elseif ($searchResults.Length -gt 1)
{
    $Context.LogMessage("Found more than one Property Pattern with the following name: '$patternName'.", "Warning")
    return
}
$propertyPatternPath = $searchResults[0].AdsPath

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

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

$values = New-Object "System.Collections.ArrayList"
foreach ($searchResult in $searchResults)
{
    [void]$values.Add($searchResult.Properties[$propertyForList].Value)
}

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

foreach ($item in $pattern.Items)
{
    if ($item.PropertyName -ieq $propertyToUpdate)
    {
        $pattern.Items.Remove($item)
        break
    }
}

if ($values.Count -eq 0)
{
    return
}

# 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()
$constraints.Add($constraint)
$item.SetConstraints($constraints)

# Save the changes
$item.SetInfo()
$pattern.Items.Add($item)
0

Worked perfectly, thanks for the help!

Related questions

0 votes
1 answer

In AdaxesConfig>Management>Forms and Views>User form - We want the ability to for Department field, when we click Configure to look similar to Manager (when it is configure is ... . I wanted to add some screenshots but didn't see the option to do it.

asked Feb 17, 2023 by mchaudh (40 points)
0 votes
1 answer

Is it possible to populate Custom Command Drop-Down List and Checkbox List items using PowerShell? If not, is such a feature on the Adaxes roadmap?

asked Dec 12, 2022 by Viajaz (210 points)
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 (60 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)
3,547 questions
3,238 answers
8,232 comments
547,809 users