Tag Archives: group

Windows: Get all groups a user is memberof by dsquery/dsget recursive


The “net” builtin commands of Windows have some limitations: It truncates groupnames longer then 20 Characters, it cannot resolve group in group memberships….

dsget/dsquery are (LDAP) command line interfaces for active directory. For using these commands you have to install the Windows RSAT Tools (Remote Server Administration Tools).

Some examples.
Continue reading Windows: Get all groups a user is memberof by dsquery/dsget recursive

Advertisment to support michlstechblog.info

Powershell: List members of an Active Directory Group


here are the code snippets to list all members of an Active Directory Group.

Some constants

# Define LDAP search root, the Global catalog of the domain
# The Groupname to looking for

Continue reading Powershell: List members of an Active Directory Group

Windows: Create a new local User Account and add them to a local group by using .NET and C#


a short post. It describes how to create a new local Windows User account and add them to an existing local user group.

First of all, include the following references in your project:

using System.DirectoryServices;
using System.Runtime.InteropServices;

Create a new User with local administrator rights.

// define Username and Password
const string USER_NAME = "NewAdmin";
char[] aPWchars = { 'P', 'a', 's', 's' , 'w', 'o', 'r', 'd'};
System.Security.SecureString oPW = new System.Security.SecureString();
foreach (char cChr in aPWchars) {
// Get Computerobject via ADSI
DirectoryEntry oComputer = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
// New User
DirectoryEntry oNewUser = oComputer.Children.Add(USER_NAME, "user");
// define Pointer to a string
IntPtr pString = IntPtr.Zero;
// Pointer to password
pString = Marshal.SecureStringToGlobalAllocUnicode(oPW);
// Set password
oNewUser.Invoke("SetPassword", new object[] { Marshal.PtrToStringUni(pString) });
// Add a description
oNewUser.Invoke("Put", new object[] { "Description", "New Administrator" });
// Save changes
// Cleanup and free Password pointer
// Get Group
DirectoryEntry oGroup = oComputer.Children.Find("Administrators", "group");
// And add the recently created user
oGroup.Invoke("Add", new object[] { oNewUser.Path.ToString() });