🟣 C# / .NET 6+
Get Local Groups Report (C#)
Queries Win32_Group via WMI (System.Management) and prints Local Groups to the console.
GetGroupReport.cs
// GetGroupReport.cs
//
// Reports Local Groups via WMI (Win32_Group).
//
// Requires the System.Management package:
// dotnet new console -o GroupReport
// dotnet add package System.Management
// (replace the generated Program.cs with this file, then dotnet run)
// On .NET Framework, System.Management is already available — just
// add a reference to it in your project.
using System;
using System.Management;
var searcher = new ManagementObjectSearcher("SELECT Name, Description, Domain FROM Win32_Group");
int count = 0;
foreach (ManagementObject item in searcher.Get())
{
Console.WriteLine($"Name: {item["Name"]}");
Console.WriteLine($"Description: {item["Description"]}");
Console.WriteLine($"Domain: {item["Domain"]}");
Console.WriteLine(new string('-', 40));
count++;
}
if (count == 0)
{
Console.WriteLine("No Local Groups found.");
}
else
{
Console.WriteLine($"\n{count} Local Groups found.");
}