0 votes

Hallo,
I'm trying to build a function that will have two parameters $Containrer and $Filter
$filter - is a LDAP filer that serach some specific objects
$Containrer - is a container in which $filter should looks for object
Function shoud return list of distinguishedNames ob finded objects
So at first I try make some simple code to transform it into function but I dosn't work.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")
$userSAM = "%samaccountname%"
$searcher = $admService.OpenObject("Adaxes://$GroupsContainerDN", $NULL, $NULL, 0)
$searcher.SearchFilter = "(&(objectClass=group)(extensionAttribute1=$userSAM))"
$searcher.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.SetPropertiesToLoad(@("distinguishedName"))
$searchResults = $searcher.ExecuteSearch()
$array = @{}
foreach ($object in $searchResults.FetchAll())
{
$DN = $object.Properties["distinguishedName"].value
$array += $DN
}
$searchResults.Dispose()

The code should returned a list of DN's , but I got "You can add another hash table only to a hash table'
Seams that $DN is treated by powershell as a hash table, is it possible to workoroud it somhow?

by (510 points)

1 Answer

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

Hello,

You are declaring $array as a hash table, but trying to work with it as with an array. To remedy the issue, you need to declare it as an array. To do this, replace the following line:
$array = @{}
with the following:
$array = @()

Related questions

0 votes
1 answer

Using the powershell module, I know how to create a scheduled task, and also how to bind to a scheduled task that is already known. I also have used code to try creating ... same time as another. These are all one-time tasks and will be removed once executed.

asked Jan 19 by aweight (60 points)
0 votes
1 answer

Hello! We are currently trying to use the REST API to search for all group objects in our domain, but the search result is only returning 1000 objects. We tried supplying a ... the request. Is there a way to retrieve more than 1000 objects using the REST API?

asked Feb 16, 2022 by KelseaIT (320 points)
0 votes
1 answer

I need to send an e-mail to the owner ("managed by") for each group. The e-mail should contain a list of group members. What is the best way to do that?

asked May 9 by akindy (40 points)
0 votes
1 answer

Have a csv file of users that I need to import into Adaxes. I had initially found an article for this, but upon going today, it gave me an error (looks like it was deleted). Thank you

asked Nov 19, 2022 by wangl (20 points)
0 votes
1 answer

Hello, I need to check, from a csv file, if users exist or not. I do not have the login name but only the atributs Name givenName The output must be another csv file ... " --> False or True Is there an Adaxes script existing doing this? Thanks in advance!

asked Feb 4, 2019 by tentaal (1.1k points)
3,588 questions
3,277 answers
8,303 comments
548,092 users