0 votes

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 with a column "exists" --> False or True

Is there an Adaxes script existing doing this?

Thanks in advance!

by (1.1k points)

1 Answer

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

Hello,

You can use the below script. To execute it, create a Scheduled Task configured for Domain-DNS object type and add a domain to the Activity Scope. The task will create a CSV file containing a column specifying whether a user with such a name is present in your environment. In the script:

  • $sourceCSVFilePath – specifies the path to the source CSV file;
  • $targetCSVFilePath – specifies the path to the resulting CSV file;
  • $identityColumnName – specifies the name of the column in the source file that store names of users;
  • $identityPropertyName – specifies the LDAP name of the property whose values will be compared to the values stored I the columns specified in the $identityColumnName variable;
  • $statusColumnName – specifies the name of the column that will store user account statuses in the resulting CSV file.
$sourceCSVFilePath = "\\Server\Share\Users.csv" # TODO: modify me
$targetCSVFilePath = "\\Server\Share\Report.csv" # TODO: modify me
$identityColumnName = "Name" # TODO: modify me
$identityPropertyName = "name" # TODO: modify me
$statusColumnName = "Exists" # TODO: modify me

# Import CSV
$records = Import-Csv -Path $sourceCSVFilePath

# Specify settings for user search
$searcher = $Context.BindToObject("Adaxes://RootDSE")
$searcher.PageSize = 500
$searcher.VirtualRoot = $True

$usersFromCSV = @{}
$filter = New-Object "System.Text.StringBuilder"
foreach ($record in $records)
{
    $userIdentity = $record.$identityColumnName
    $record | Add-Member -MemberType NoteProperty -Name $statusColumnName -Value "False"
    $usersFromCSV.Add($userIdentity, $record)

    [void]$filter.Append("($identityPropertyName=$userIdentity)")
    $remainder = 0
    [void][System.Math]::DivRem($i, 500, [ref]$remainder)
    if ((($i -ne 0) -and ($remainder -eq 0)) -or ($i -eq $importedUsers.Length - 1))
    {
        # Search users
        $searcher.SearchFilter = "(&(sAMAccountType=805306368)(|" + $filter.ToString() + "))"
        try
        {
            $searchResultIterator = $searcher.ExecuteSearch()
            $searchResults = $searchResultIterator.FetchAll()

            foreach ($searchResult in $searchResults)
            {
                $userIdentity = $searchResult.Properties[$identityPropertyName].Value
                if ($usersFromCSV[$userIdentity] -eq $NULL)
                {
                    continue
                }

                $usersFromCSV[$userIdentity].$statusColumnName = "True"
            }
        }
        finally
        {
            # Release resources
            if ($searchResultIterator) { $searchResultIterator.Dispose() }
        }

        # Clear filter
        $filter.Length = 0
        $filter.Capacity = 0
    }
}

$usersFromCSV.Values | Export-Csv -Path $targetCSVFilePath -NoTypeInformation
0

Thank you :-)

Pass list of users to check if they're disabled

Related questions

0 votes
0 answers

Hello, Is it possible to pass a comma-separated list of users (firstname.lastname or emails) in a parameter instead of a CSV? How does it translate to an array of usernames ... in the Adaxes interface. Or can the script only email the list of disabled users?

asked Oct 25, 2022 by manomano (80 points)
0 votes
1 answer

In our organization, we have two domains. Is there a way to create a rule to check the other domain if the account exists before creating the account?

asked Mar 28, 2013 by Kikaida (1.1k points)
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

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

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 ... is treated by powershell as a hash table, is it possible to workoroud it somhow?

asked Aug 12, 2015 by axmaster (510 points)
3,588 questions
3,277 answers
8,303 comments
548,090 users