Export all the computers name in active directory including all OUs

Hi All ,

I would like to run a PS script to output the below please

1. first script is to output all the computer name in active directory in all OUS

2. to export all the below attribute please

Compute name in all OUs in active directory
Canonical name of object ( which OU I can find this computer )
created date
modified
Last log on date
pwd last set

I appreciate your quick response

thanks
RabihhajIT HelpDeskAsked:
Who is Participating?
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.

Benjamin VoglarIT ProCommented:
get-aduser -Filter * -Property SamAccountName,Lastlogon,LastlogonTimeStamp,Modified,passwordlastset | Select Name,UserPrincipalname,SamAccountName,@{Name='Last Logon Timestamp';Expression={[System.DateTime]::FromFileTime($_.LastLogonTimestamp).ToString('g')}},@{Name='Last Logon';Expression={[System.DateTime]::FromFileTime($_.LastLogon).ToString('g')}},@{Name='Last Modified';Expression={[System.DateTime]::FromFileTime($_.Modified).ToString('g')}},@{Name='Password last set';Expression={[System.DateTime]::FromFileTime($_.passwordlastset).ToString('g')}},DistinguishedName
0
RabihhajIT HelpDeskAuthor Commented:
I would like to test it first on a single computer name , please assist
before I run this script

could you please confirm is the above script will export computers name or user ID

thanks
0
footechCommented:
Get-ADComputer -Filter * -Properties Canonicalname,WhenCreated,WhenChanged,LastLogonDate,PasswordLastSet |
Select Name,Canonicalname,WhenCreated,WhenChanged,LastLogonDate,PasswordLastSet

Open in new window

If you want to save to a file, one option is to export to a .CSV.  You could just add the following to the last line:
| Export-CSV computerinfo.csv -notype

Open in new window

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
Hey MSSPs! What's your total cost of ownership?

WEBINAR: Managed security service providers often deploy & manage products from a variety of solution vendors. But is this really the best approach when it comes to saving time AND money? Join us on Aug. 15th to learn how you can improve your total cost of ownership today!

Benjamin VoglarIT ProCommented:
I forgot to export everything.

get-aduser -Filter * -Property SamAccountName,Lastlogon,LastlogonTimeStamp,Modified,passwordlastset | Select Name,UserPrincipalname,SamAccountName,@{Name='Last Logon Timestamp';Expression={[System.DateTime]::FromFileTime($_.LastLogonTimestamp).ToString('g')}},@{Name='Last Logon';Expression={[System.DateTime]::FromFileTime($_.LastLogon).ToString('g')}},@{Name='Last Modified';Expression={[System.DateTime]::FromFileTime($_.Modified).ToString('g')}},@{Name='Password last set';Expression={[System.DateTime]::FromFileTime($_.passwordlastset).ToString('g')}},DistinguishedName  | Export-CSV  c:\it\test.csv
0
RabihhajIT HelpDeskAuthor Commented:
Hi Footech,

I missed one column please . can we get who is the last user logged in to the PC ( full name or userID ) also location if that possible please

thanks
0
footechCommented:
Last logged on user is not an attribute.  There are different approaches for figuring it out, but you should ask a new question for that.
To add location:
Get-ADComputer -Filter * -Properties Canonicalname,WhenCreated,WhenChanged,LastLogonDate,PasswordLastSet,Location |
Select Name,Canonicalname,WhenCreated,WhenChanged,LastLogonDate,PasswordLastSet,Location

Open in new window

The order of the properties listed with the Select-Object command determines what order they will appear in your .CSV.
0
RabihhajIT HelpDeskAuthor Commented:
good answer
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.

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.