
First, you need to install the NuGet Package System.DirectoryServices.AccountManagement
Now you can open a context and get all members of the built-in group “Administrators”
1// This works only on Windows!
2using System.DirectoryServices.AccountManagement;
3using (PrincipalContext ctx = new PrincipalContext(ContextType.Machine))
4using (GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, "Administrators"))
5{
6 if (grp is not null)
7 {
8 Console.WriteLine("Output:");
9 foreach (Principal p in grp.GetMembers(recursive: true))
10 {
11 Console.WriteLine(p.Name);
12 }
13 }
14}
Result:
1Output:
2Ben
3Administrator
Related articles

Mar 08, 2022 - 1 min read
.NET Updates März 2022
Heute hat Microsoft die .NET Updates von März 2022 auf ihrem Blogpost veröffentlicht. Fix CVE-2020-8927: .NET Remote Code Execution …

Feb 13, 2022 - 1 min read
20th Year! Happy Birthday .NET!
20 years ago today .NET was released! Congratulations - you are the best ecosystem!

Feb 08, 2022 - 1 min read
.NET Updates Februar 2022
Heute hat Microsoft die .NET Updates von Februar 2022 auf ihrem Blogpost veröffentlicht. Fix CVE-2022-21986: .NET Denial of Service …
Let's Work Together
Looking for an experienced Platform Architect or Engineer for your next project? Whether it's cloud migration, platform modernization or building new solutions from scratch - I'm here to help you succeed.
