0 votes

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.

$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"
$searchResults = $searcher.ExecuteSearch()
$array = @{}
foreach ($object in $searchResults.FetchAll())
$DN = $object.Properties["distinguishedName"].value
$array += $DN

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


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

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

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)
0 votes
1 answer

Hello, We did implement LAPS & Bitlocker in our AD environment. To let the helpdesk retrieve those information, we created a bunch a custom command that fetch the AD and log ... mail, but this is not possible as we have a "no password per email" policy

asked Mar 20, 2017 by Pierre (750 points)
0 votes
1 answer

Any idea why Softerra.Adaxes.Adsi.Search.DirectorySearcher is not getting loaded? PS C:\Windows\system32> [Reflection.Assembly]:: ... Object], PSArgumentException + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

asked Aug 14, 2019 by Brajesh (460 points)
2,993 questions
2,712 answers
203,586 users