$ldapQuery = "(&(objectCategory=computer))"
$de = new-object system.directoryservices.directoryentry
$ads = new-object system.directoryservices.directorysearcher -argumentlist $de,$ldapQuery
$complist = $ads.findall()
$complist | % {
    $cn = $_.properties['cn']
    $rk = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$cn)
    $rv = $rk.opensubkey("\Software\Microsoft\Windows NT\CurrentVersion\WinLogon")
    $lastuser = $rv.GetValue("DefaultDomainName") + "\" + $rv.GetValue("DefaultUserName")
    write-host "$cn - $lastuser"
}
