🟣 C# / .NET 6+
Get Network Login Profiles Report (C#)
Queries Win32_NetworkLoginProfile via WMI (System.Management) and prints Network Login Profiles to the console.
GetNetworkLoginProfileReport.cs
// GetNetworkLoginProfileReport.cs
//
// Reports Network Login Profiles via WMI (Win32_NetworkLoginProfile).
//
// Requires the System.Management package:
// dotnet new console -o NetworkLoginProfileReport
// 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, LastLogon, NumberOfLogons FROM Win32_NetworkLoginProfile");
int count = 0;
foreach (ManagementObject item in searcher.Get())
{
Console.WriteLine($"Name: {item["Name"]}");
Console.WriteLine($"LastLogon: {item["LastLogon"]}");
Console.WriteLine($"NumberOfLogons: {item["NumberOfLogons"]}");
Console.WriteLine(new string('-', 40));
count++;
}
if (count == 0)
{
Console.WriteLine("No Network Login Profiles found.");
}
else
{
Console.WriteLine($"\n{count} Network Login Profiles found.");
}