c# - OU timestamp ComObject -
here sample code have finds computer objects in ou. when print out property fields, system.__comobject
several of values such lastlogon
, lastlogontimestamp
, pwdlastset
, usnchanged
, etc. assume these date-ish type values of sort.
how date value out of it? i'd c# solution not powershell solution such this: https://sweeneyops.wordpress.com/2012/06/11/active-directory-timestamp-conversion-through-powershell/
thanks
using (directoryentry entry = new directoryentry("ldap://" + ou)) { using (directorysearcher searcher = new directorysearcher(entry)) { searcher.filter = ("(objectclass=computer)"); searcher.sizelimit = int.maxvalue; searcher.pagesize = int.maxvalue; foreach (searchresult result in searcher.findall()) { directoryentry computer = result.getdirectoryentry(); foreach(string propname in computer.properties.propertynames) { foreach(object value in computer.properties[propname]) { console.writeline($"{propname}: {value}"); } } } } }
i know there long inside of object can use datetime.fromfiletime(longtype)
date out of it.
what need add com reference "active ds type library"
then following code make date time out of 1 of fields, example "pwdlastset"
iadslargeinteger largeint = (iadslargeinteger)computer.properties["pwdlastset"][0]; long datelong = (((long)largeint.highpart) << 32) + largeint.lowpart; datetime pwset = datetime.fromfiletimeutc(datelong);
Comments
Post a Comment