I wrote the script below on how to get the last logon users from the registry. I would like to add PSComputerName, last logon time, format it and export to a CSV file, help would really be appreciated .
$computer = Get-Content -path 'C:\Users\Public\Computer\computers.txt'
Invoke-Command -ComputerName $computer -ScriptBlock {
$regpath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI'
$regvalue = Get-ItemProperty -Path $regpath
$regvalue.LastLoggedOnUser
$regvalue.LastLoggedOnDisplayName
}