Computers report, How to export with PowerShell all computers from Ad with last logon time stamp, os , etc.

How to export with PowerShell all computers from Ad with last logon time stamp, os , etc, create a report and compare with SCCM inventory.

Many times as an enterprise mobility consultant I need to have a clear picture about companies computer environment. One example is to export all windows clients from ad and history of last time computers contact the ad. Than compre this list with SCCM or Intune.

First let’s export for example all windows 10 from AD and drop them in a csv file.

PowerShell command:

Get-ADComputer -Filter  {OperatingSystem -Like '*10*' } -Properties lastlogondate,operatingsystem |select name,lastlogondate,operatingsystem | export-csv c:\temp\allcomputer.csv

{OperatingSystem -Like '*10*' } , this will filter al windows 10, you can change for example with {OperatingSystem -Like '*Server*' } to export only servers

Lastlogondate , is when last time computer contact the AD, in other words when computer was active in AD last time. If this time is longer than 180 days maybe this computer was removed from your environment.

I have made than a excel with two sheets, on sheet with all discovered computers in AD and the second with all managed computers in SCCM. Using VLOOKUP I highlighted in all discovered computers those not managed by SCCM

=IFERROR(VLOOKUP(A1,SCCM!A:A,1,FALSE),"No")

Name

lastlogondate

operatingsystem

In SCCM

WIN10VM-TEST

17/04/2019 10:08

Windows 10 Enterprise

No

This example shows on VM is in AD, last time activity was 4 months a go and si not in SCCM, probably a test machine who wasn’t properly decommissioned (also disjoined from AD).

Was easy, no, happy SCCM-ing :)