diff --git a/ConfigMgrWebService/ConfigMgrWebService.asmx.cs b/ConfigMgrWebService/ConfigMgrWebService.asmx.cs index dd1751b..e9b2d13 100644 --- a/ConfigMgrWebService/ConfigMgrWebService.asmx.cs +++ b/ConfigMgrWebService/ConfigMgrWebService.asmx.cs @@ -3173,6 +3173,45 @@ public List GetADGroupsByUser(string secret, string userName) return returnValue; } + [WebMethod(Description = "Get Active Directory groups for a specific computer")] + public List GetADGroupsByComputer(string secret, string computerName) + { + MethodBase method = MethodBase.GetCurrentMethod(); + MethodBegin(method); + + //' Set return value variable + List returnValue = new List(); + + 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) {