A powerfull yet but simple powershell function written for Windows PowerShell 1.0, that queries Windows 2003 Active Directory for the last time a pc connnected to the network and communicated with Active Directory.

Copy and Paste this function into notepad. Then insert your domain information in.. LDAP://[your full domian name]/dc=[your sub domain],dc=[your domain],dc=com. for exampele:  LDAP://office.test.com/dc=test,dc=office,dc=com

Then copy from notepad and paste into the powershell console window.

function get-lastCompLogon([string] $compName)
{
                $computerName = $compName
                if($computerName){$input = $computerName}
                $srchRoot = new-object system.directoryservices.directoryentry “LDAP://[your full domian name]/dc=[your sub domain],dc=[your domain],dc=com”
                $srchr = new-object system.directoryservices.directorysearcher $srchRoot
                $srchr.Filter = “(&(objectclass=computer)(Name=$input*))”
                $srchr.pagesize = 10000
                $srchr.PropertiesToLoad.Clear()
                $sr = $srchr.FindOne()
               
                if($sr -ne $null)
                {
                                $computerName + ” last connected to the network ” + “: `t” + ([DateTime]::FromFileTimeUtc([long]$sr.Properties.lastlogontimestamp[0]).ToLocalTime()).ToString()
                }
               
}

Press enter twice .

Then type:  get-lastcomplogon computerNamecomputername should be replaced by the name of the host in question for example:get-lastcomplogon testpcshould return somthing that looks like:testpc last connected to the network :  11/05/2007  11:02:30 AM

Tags:
Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

counter