Link to home
Create AccountLog in
Avatar of Rabih El Haj youssef
Rabih El Haj youssefFlag for Australia

asked on

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
Avatar of Benjamin Voglar
Benjamin Voglar
Flag of Slovenia image

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
Avatar of Rabih El Haj youssef

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
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
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.
good answer