Deleting User From Active Directory c#.net

Introduction 
 
I have written an application for deleting accounts from the Active Directory wrapper.
 
  1. public static string DelUserInAD(string sGroupName, string strDomain, string strName)  
  2.         {  
  3.             bool done = false;  
  4.   
  5.             string result = string.Empty;  
  6.             try  
  7.             {  
  8.                 PrincipalContext oPrincipalContext = GetPrincipalContext();  
  9.                 string sUserName = strDomain + "\\" + strName;  
  10.                 UserPrincipal oUserPrincipal = UserPrincipal.FindByIdentity(oPrincipalContext, sUserName);  
  11.                 GroupPrincipal oGroupPrincipal = GetGroup(sGroupName);  
  12.                 if (oUserPrincipal != null && oGroupPrincipal != null)  
  13.                 {  
  14.                     if (IsUserGroupMember(sUserName, sGroupName))  
  15.                    {  
  16.                         //oGroupPrincipal.Members.Add(oUserPrincipal);  
  17.                         //oGroupPrincipal.Save();  
  18.                         oGroupPrincipal.Members.Remove(oUserPrincipal);  
  19.                         oGroupPrincipal.Save();  
  20.                         done = !(oUserPrincipal.IsMemberOf(oGroupPrincipal));  
  21.   
  22.                     }  
  23.                     else  
  24.                     {  
  25.                        result = sUserName + " already exists. Exiting!!";  
  26.                     }  
  27.                 }  
  28.   
  29.             }  
  30.             catch  
  31.             {  
  32.   
  33.             }  
  34.             return result;  
  35.         }  
Ebook Download
View all
Learn
View all