Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions ConfigMgrWebService/ConfigMgrWebService.asmx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3173,6 +3173,45 @@ public List<ADGroup> GetADGroupsByUser(string secret, string userName)
return returnValue;
}

[WebMethod(Description = "Get Active Directory groups for a specific computer")]
public List<ADGroup> GetADGroupsByComputer(string secret, string computerName)
{
MethodBase method = MethodBase.GetCurrentMethod();
MethodBegin(method);

//' Set return value variable
List<ADGroup> returnValue = new List<ADGroup>();

if (secret == secretKey)
{
//' Log that secret key was accepted
WriteEventLog("Secret key was accepted", EventLogEntryType.Information);

try
{
//' Get AD computer object
string computerDistinguishedName = GetADObject(computerName, ADObjectClass.Computer, ADObjectType.distinguishedName);

//' Get AD groups for computer distinguished name
ArrayList groupMemberships = new ArrayList();
ArrayList groups = GetADAttributeValues("memberOf", computerDistinguishedName, groupMemberships, true);

foreach(string group in groups)
{
string attributeValue = GetADAttributeValue(group, "samAccountName");
returnValue.Add(new ADGroup() { DistinguishedName = group, samAccountName = attributeValue });
}
}
catch (Exception ex)
{
WriteEventLog($"An error occurred while retrieving Active Directory group memberships for user. Error message: {ex.Message }", EventLogEntryType.Error);
}
}

MethodEnd(method);
return returnValue;
}

[WebMethod(Description = "Set the description field for a computer in Active Directory")]
public bool SetADComputerDescription(string secret, string computerName, string description)
{
Expand Down