List of users and computers name from active directory

Hello all,

How to export users, computer name, first name, last name from Active directory.
I want to have a excel report of machine names, user name, first name and last name in my domain.

Regards
A SAsked:
Who is Participating?
 
AlanConnect With a Mentor ConsultantCommented:
Good question Yo-Bee!


Hi A S,

Users and Computers are two different objects in ActiveDirectory - they are not linked, even though (physically), one user might (nearly) always log in at one machine.

If you are looking for a record of who logs in where, then you can't get that from ActiveDirectory (at least not as far as I know but I would be happy to learn how if it is possible).

You could create such a record though.  It would only cover the period from whenever you start it of course.

You could put something like this in the user login script to get a CSV file that you could then open in Excel and play around with filtering / sorting etc:

Echo %UserName%, %ComputerName%, %Date%, %Time% >> \\Server\Share\RecordOfUserLoginsToMachines.csv

Open in new window


The network share would have to have appropriate permissions of course.

I do this on some networks, and then move the CSV file to a secure archive location as a scheduled job overnight (or more often if you prefer).  It can be useful if you lose track of who is logging in where.  I had one client that wanted the log file copied to a secure location every minute, which I did setup, but I also told them that if they have such major trust issues with their staff, then I perhaps there were much more significant issues of culture and recruitment than any IT issues.  I raised their fees quite a bit not too long after, and they chose to move elsewhere :-)


Alan.


NB:  This was not my idea originally, but I cannot recall where I got it from, so this is a nod to the unknown person that first thought of it.


PS:  It occurs to me that you could also query the computer security logs, but I am not sure how easy that would be to get what you want in a single Excel file.
0
 
AlanConsultantCommented:
Hi,

You could use the following two commands (change the destination to wherever makes sense for you):

Get-ADComputer -Filter * | Format-List -Property * | Out-File -Width 1000 C:\Computers.txt
Get-ADUser -Filter * | Format-List -Property * | Out-File -Width 1000 C:\Users.txt

Open in new window



Alan.
1
 
yo_beeDirector of Information TechnologyCommented:
Are you looking to cross-reference users-to-computers ?
1
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
yo_beeDirector of Information TechnologyCommented:
The only issue I can see with that logon script is the file is open at the time the script is trying to write to it.
0
 
A SAuthor Commented:
Thanks Alan
0
 
AlanConsultantCommented:
Hi A S - Glad to help.

@Yo_Bee:  Yes - that is an issue.  I have only implemented this on small networks where the chances are relatively low, but you are definitely correct that it could be a problem.

I guess it would be possible to create a separate CSV file for each user or computer, having them all in one location.

It would not be difficult to then either join up the CSV files, and open in Excel, or have Excel pull in the data from each CSV, either to one sheet, or one sheet per CSV, and analyse it that way.

If practical, I would prefer to have it all in one CSV file or aggregated into a single worksheet.


Alan.
0
 
yo_beeDirector of Information TechnologyCommented:
Actually looking at this now that script will overwrite each time it runs.
0
 
AlanConsultantCommented:
Hi Yo_Bee,

No - it appends the new line of data to the end of the file each time it runs.

Note the double 'greater than' symbols.  If you only had one, it would over-write / replace, but with two it appends.

I don't have this running on any networks right now, so I am going to put it into the login script of my own to test, but I am sure that is what I did before, and it worked across multiple different networks.  The only possibility is that Server 2016 and / or Win10 is different than older versions, but I doubt it.

Alan.
0
 
yo_beeDirector of Information TechnologyCommented:
Nice. I did not know that.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.