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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
AlanConsultantCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.