Tuesday, August 2, 2016

PowerShell for Domain Systems Information Reports

With normal network maintenance and hardware replacement cycles it is a good idea to keep an eye on the age and other information of the computers on your network. There are lots of third party tools to run more detailed reports, but if you want a quick report why not use PowerShell on Server 2012 and export to a CSV file.

Open up PowerShell as an administrator and review the Get-ADComputer commands

Get-ADComputer -Filter *

Will show you basic AD attributes of the systems:


Get-ADComputer -Filter * -Properties * will give you way too much information but shows you all the possible variables you can choose from. Below are some of the more common properties you would likely want to query for reports:




Now to run the following command to see the fully qualified computer names, the date and time they were created in AD, along with last logon date and time:

Get-ADComputer -Filter * -Properties "DNSHostName","Created","LastLogonDate" |select dnshostname,created,lastlogondate


Note: This just shows when created/joined to the domain it is not a confirmation of the computers true age. That will require further research but typically this will provide the ballpark needed.

Now to run the command again but this time export the data we want to a CSV file in C:\Temp\ that can be more easily viewed, edited and sorted in Excel.

Get-ADComputer -Filter * -Properties "DNSHostName","Created","LastLogonDate" |select dnshostname,created,lastlogondate |Export-csv C:\temp\computerdata.csv


Note: It creates a “#TYPE Selected.Microsoft.ActiveDirectory.Management.ADComputer” field on Line 1A you can delete.

Using the example above you can add or remove properties to your report. For example I will add operating system information and change the fully qualified computer name to the shorter “Name”:

Get-ADComputer -Filter * -Properties "Name","Created","LastLogonDate",”OperatingSystem” |select name,created,lastlogondate, operatingsystem |Export-csv C:\temp\computerdata.csv


This should provide you quick answers you need regarding your systems

Happy Querying!

Reference: Ed Buford

No comments:

Post a Comment