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 (5.6k points)

1 Answer

0 votes
by (182k 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 (4.8k 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 (2.7k 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 (710 points)
0 votes
1 answer

Hello, I have a web service that checks if a user is a member of a group. I am not concerned if they are a direct member or an indirect member of a group, but if the user is in the ... I pass it User A and Group 1. I am using ADSI, c# (.Net 4.0), and WCF.

asked Feb 23, 2014 by mbcalvin (1.1k points)
0 votes
2 answers

Hi, Can you tell me how to look up a list of last logged-in users for computers from specific OU? Have OU called Laptops and need to know who as last person logged into ... username-of-last-user-who-lgged-on-to-computer-s269.htm but it' s not design for OU

asked Dec 2, 2019 by roberttryba (450 points)
2,251 questions
2,011 answers
5,504 comments
24,668 users