PS script to get Windows 10 clients name and win version, and also get the last logged in SamAccountName on clients and export all into excell.xlmx document


I hope someone inhere can help me designing af powershell script which does the following:


1) - Find all windows 10 clients in AD, and get thier windows version.

Then also get the either SamAccountName OR last SamAccountName logged in on the found windows 10 clients!

2) - Export Last login "SamAccountName", "OperationSystem" and "OperationSystemVersion" to an excell document.


I have the following code sofar:


Import-Module ActiveDirectory

Get-ADComputer -Filter * -Property * | Select-Object Name,OperatingSystem,OperatingSystemVersion | Export-CSV C:\AllWindows1.csv -NoTypeInformation -Encoding UTF8


But i need this to fetch the logged in/last login of the SamAccountName also on the windows 10 clients in the AD, and also export this to an excell.xlmx, if possible.

Can anyone help me?

Best regards