Created
August 21, 2009 17:33
-
-
Save program247365/172213 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.DirectoryServices; | |
using System.DirectoryServices.AccountManagement; | |
namespace ActiveDirectoryAccountLockOut | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var name = "PUTYOURADUSERNAMEHERE"; | |
try | |
{ | |
using (var context = new PrincipalContext(ContextType.Domain)) | |
{ | |
using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, name)) | |
{ | |
if (user.IsAccountLockedOut()) | |
{ | |
Console.Write("Yes Locked out."); | |
Console.Write(Environment.NewLine + "Locked Out Time: " + user.AccountLockoutTime); | |
//Console.Write(user.AccountLockoutTime.ToString()); | |
//user.UnlockAccount(); | |
} | |
else | |
{ | |
Console.Write("Not locked out!"); | |
} | |
} | |
} | |
} | |
catch (Exception ex) | |
{ | |
Console.Write(ex.Message + Environment.NewLine + ex.StackTrace); | |
} | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment