How to get a user’s e-mail address from Active Directory?

Disclaimer: This code doesn’t search for a single exact match, so for domain\j_doe it may return domain\j_doe_from_external_department‘s email address if such similarly named account also exists. If such behaviour is undesirable, then either use a samAccountName filter intead of an anr one used below or filter the results additionally. I have used this code successfully … Read more

GRANT syntax for domain\user

Assuming you have created a user in this database associated with the AD login, e.g. CREATE LOGIN [domain\user] FROM WINDOWS; GO USE your_database; GO CREATE USER [domain\user] FROM LOGIN [domain\user]; GO Then you merely have to follow the same syntax. Because \ is not a standard character for an identifier, you need to escape the … Read more

Converting LastLogon to DateTime format

DateTime.FromFileTime should do the trick: PS C:\> [datetime]::FromFileTime(129948127853609000) Monday, October 15, 2012 3:13:05 PM Then depending on how you want to format it, check out standard and custom datetime format strings. PS C:\> [datetime]::FromFileTime(129948127853609000).ToString(‘d MMMM’) 15 October PS C:\> [datetime]::FromFileTime(129948127853609000).ToString(‘g’) 10/15/2012 3:13 PM If you want to integrate this into your one-liner, change your select … Read more

How to connect with Java into Active Directory

Here is a simple code that authenticate and make an LDAP search usin JNDI on a W2K3 : class TestAD { static DirContext ldapContext; public static void main (String[] args) throws NamingException { try { System.out.println(“Début du test Active Directory”); Hashtable<String, String> ldapEnv = new Hashtable<String, String>(11); ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY, “com.sun.jndi.ldap.LdapCtxFactory”); //ldapEnv.put(Context.PROVIDER_URL, “ldap://societe.fr:389”); ldapEnv.put(Context.PROVIDER_URL, “ldap://dom.fr:389”); ldapEnv.put(Context.SECURITY_AUTHENTICATION, “simple”); … Read more

tech