Guest User

Untitled

a guest
Jan 12th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. wpkg = "CN=" + pkg + ",OU=Software,OU=Groups,OU=blah blah";
  2. //wpkg = "LDAP://CN=" + pkg + ",OU=Software,OU=Groups,OU=blah blah";
  3.  
  4. **// the following code works and finds what I am looking for****
  5. DirectoryEntry entry = new DirectoryEntry("LDAP://" + ouPath);
  6. DirectorySearcher search = new DirectorySearcher(entry);
  7. search.Filter = "(CN=" + cn + ")";
  8. search.PropertiesToLoad.Add("memberOf");
  9.  
  10. SearchResult result = search.FindOne();
  11. **This finds the computer I am looking for**
  12. if (result != null)
  13. {
  14. DirectoryEntry entryToUpdate = result.GetDirectoryEntry();
  15.  
  16. entryToUpdate.Username = un;
  17. entryToUpdate.Password = pass;
  18.  
  19. **I want to add a value to the memberOf property**
  20.  
  21. entryToUpdate.Properties["memberOf"].Add(wpkg);
  22. entryToUpdate.CommitChanges();
  23.  
  24. ***I get System.DirectoryServices.DirectoryServicesCOMException: "The
  25. **server is unwilling to process the request.**
  26. **regardless if I have "LDAP://" in wpkg or not
  27.  
  28. entryToUpdate.Invoke("Add", new object[] {wpkg});
  29. **I get System.Runtime.InteropServices.COMException: "Unknown name. Exception from HRESULT:0x800200006 (DISP_E_UNKNOWNNAME))"**
  30. **regardless if I have "LDAP://" in wpkg or not
  31.  
  32. entryToUpdate.CommitChanges();
  33.  
  34. //entryToUpdate.Properties["memberof"].Value = "";
  35. //entryToUpdate.Properties["memberof"].Clear();
  36. entryToUpdate.Invoke("remove", new object[] { wpkg });
Add Comment
Please, Sign In to add comment