How to Use PowerShell for Domain Systems Information Reports

With normal network maintenance and hardware replacement cycles, it is best practice to also keep an eye on the age and other information of the computers that are on your network. There are lots of third-party tools that run more detailed reports, but for a quick report you can easily use PowerShell on Server 2012 and export to a CSV file. Here’s how you do it …

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

Get-ADComputer -Filter * will show you basic AD attributes of the systems:

PowerShell for domain systems

Get-ADComputer -Filter * -Properties * will give you way too much information, but shows you all the possible variables you can choose from.

Here are some of the more common properties you may want to query for reports:

PowerShell for domain systems

PowerShell for domain systems

clip_image008[4]

Next, 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

PowerShell for domain systems

Note: This just shows when the computer names were created/joined to the domain — it is not a confirmation of the computer’s true age. That will require further research, but typically this will provide the ballpark number you need.

Now, run the following command in order to 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

PowerShell for domain systems

Note: It creates a “#TYPE Selected.Microsoft.ActiveDirectory.Management.ADComputer” field on Line 1A that 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

PowerShell for domain systems

This should provide quick answers you need regarding your systems.

Happy querying!

If you have any questions about using PowerShell for your Domain Systems Information Reports, don’t hesitate to reach out. You can email us or give us a call at 502-240-0404!