Get-ADUser -Filter

Roger Roger 7,181 Reputation points
2021-10-27T21:54:07.847+00:00

Hi All

i have a csv file with FirstName and LastName, i want to import this csv file and get the users samaccountname,upn and email addresses exported to csv file, experts guide me in pulling this information.
144220-capture.jpg

Windows for business Windows Client for IT Pros Directory services Active Directory
Windows for business Windows Server User experience PowerShell
Windows for business Windows Server User experience Other
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 47,901 Reputation points
    2021-10-27T22:48:01.383+00:00

    What you ask is pretty straightforward. Here's an example (replace the property names in the Select-Object with the ones you want):

    Import-Csv c:\junk\file.csv |
        ForEach-Object{
            Get-ADUser -Filter "givenname -eq '$($_.FirstName)' -and surname -eq '$($_.LastName)'" |
                Select-Object property1, property2, etc.
        } | Export-Csv c:\junk\anotherfile.csv
    

    However, there are no guaranties that the combination of given-name and surname are unique in your Active Directory. You may get more than one user from the Get-ADUser -- and that may require you to modify the example to handle that (it's not difficult). But you should rethink how you identify users and use a property that would uniquely identify them. That may be a easy as using their e-mail addresses (which are guaranteed to be unique).

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Roger Roger 7,181 Reputation points
    2021-10-28T04:42:16.02+00:00

    i am not getting output i am getting below

    Microsoft.ActiveDirectory.Management.ADPropertyValueCollection


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.