Skip to content

Instantly share code, notes, and snippets.

@program247365
Created August 21, 2009 17:33
Show Gist options
  • Save program247365/172213 to your computer and use it in GitHub Desktop.
Save program247365/172213 to your computer and use it in GitHub Desktop.
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