Articles
FAQs
Login
Get the all members of specified group from Active Directory
By Perry
ODBC Drivers for QuickBooks, Salesforce, SAP, MSCRM, SharePoint … Free Trial!
Use this program to retrieve all the members of specified group from AD.
Complete C# code:
-------------------
using System;
using System.IO;
using System.Text;
using System.Diagnostics;
using System.Threading;
namespace ADQuery
{
class Program
{
static void Main(string[] args)
{
string output = String.Empty;
Process DESProcess = new Process();
string privilegesGroup = "admin-group"; //Provide any group name for which you want to see members
DESProcess.StartInfo.FileName = @"C:\WINNT\system32\cmd.exe";
DESProcess.StartInfo.Arguments = " /c DSQUERY USER -samid " + privilegesGroup + " | DSGET USER -memberof";
DESProcess.StartInfo.CreateNoWindow = true;
DESProcess.StartInfo.UseShellExecute = false;
DESProcess.StartInfo.RedirectStandardInput = true;
DESProcess.StartInfo.RedirectStandardOutput = true;
DESProcess.StartInfo.WorkingDirectory = ".";
DESProcess.StartInfo.RedirectStandardError = true;
DESProcess.Start();
while (DESProcess.StandardOutput.Peek() > -1)
output = output + (DESProcess.StandardOutput.ReadToEnd()).ToString();
DESProcess.StandardOutput.DiscardBufferedData();
System.Console.WriteLine(output);
System.Console.Read();
}
}
}
Regards,
Megha
Popularity
(
1863 Views
)