Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Deleting User From Active Directory c#.net
WhatsApp
Sagar Pardeshi
11y
23.2
k
0
0
25
Blog
Introduction
I have written an application for deleting accounts from the Active Directory wrapper.
public
static
string
DelUserInAD(
string
sGroupName,
string
strDomain,
string
strName)
{
bool
done =
false
;
string
result =
string
.Empty;
try
{
PrincipalContext oPrincipalContext = GetPrincipalContext();
string
sUserName = strDomain +
"\\"
+ strName;
UserPrincipal oUserPrincipal = UserPrincipal.FindByIdentity(oPrincipalContext, sUserName);
GroupPrincipal oGroupPrincipal = GetGroup(sGroupName);
if
(oUserPrincipal !=
null
&& oGroupPrincipal !=
null
)
{
if
(IsUserGroupMember(sUserName, sGroupName))
{
//oGroupPrincipal.Members.Add(oUserPrincipal);
//oGroupPrincipal.Save();
oGroupPrincipal.Members.Remove(oUserPrincipal);
oGroupPrincipal.Save();
done = !(oUserPrincipal.IsMemberOf(oGroupPrincipal));
}
else
{
result = sUserName +
" already exists. Exiting!!"
;
}
}
}
catch
{
}
return
result;
}
Up Next
Create Directory and Copy/Save Image file on fileName from directory
Ebook Download
View all
.NET Interview Questions and Answer: Practical Implementation
Read by 41.9k people
Download Now!
Learn
View all
Membership not found