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 (220k 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 :-)

Related questions

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

When copying a group, the message appears even though the group does not yet exist. "The specified group already exists, (Server: adc.de:636)"

asked Oct 12, 2021 by Johann Ihnen (170 points)
0 votes
1 answer

Hallo everyone I have made a property with adm-CustomAttributeTextMultiValue3 and named it "School". Then I have added the values Arkades, BSLA, BSLG, BSLH, LCA, LCB, LCG, LCH ... can see an screenshot of the warning: Can anyone help me to fixs this problem?

asked Aug 15, 2019 by hilmiemrebayat (120 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)
0 votes
0 answers

Say you have Manager A that has 30 users under them. Manager A leaves and Manager B takes the position. What is the best way to update all 30 users so their new manager is Manager B.

asked Jun 7, 2021 by Jmbrown04 (60 points)
2,740 questions
2,474 answers
6,475 comments
1,371,962 users