public void Execute(IActivityRequest request, IActivityResponse response) { string userName = request.Inputs["New User Name"].AsString(); string password = request.Inputs["New User Password"].AsString(); string userDomain = request.Inputs["New User Domain"].AsString(); string ParentOU = CapitalizeLDAPPath(request.Inputs["Destination OU LDAP Path"].AsString()); string NewUserLDAPPath = string.Empty; string connectionPrefix = ParentOU; DirectoryEntry dirEntry = new DirectoryEntry(connectionPrefix, credentials.UserName + "@" + credentials.Domain, credentials.Password); DirectoryEntry newUser = dirEntry.Children.Add("CN=" + userName, "user"); try { newUser.Properties["samAccountName"].Value = userName; newUser.CommitChanges(); } catch (Exception e) { response.ReportErrorEvent("samAccountName Setting Error", e.Message.ToString()); } try { newUser.Properties["userPrincipalName"].Value = userName + "@" + userDomain; newUser.CommitChanges(); } catch (Exception e) { response.ReportErrorEvent("userPrincipalName Setting Error", e.Message.ToString()); } try { newUser.Invoke("SetPassword", new object[] { password }); newUser.CommitChanges(); } catch (Exception e) { response.ReportErrorEvent("Set Password Error", e.Message.ToString()); } try { int val = (int)newUser.Properties["userAccountControl"].Value; newUser.Properties["userAccountControl"].Value = val & ~0x2; //ADS_UF_NORMAL_ACCOUNT; newUser.CommitChanges(); } catch (Exception e) { throw e; } dirEntry.Close(); newUser.Close(); NewUserLDAPPath = newUser.Path; response.Publish("New User LDAP Path", NewUserLDAPPath); }
public void Execute(IActivityRequest request, IActivityResponse response) { string ouName = request.Inputs["New OU Name"].AsString(); string parentLDAPPath = CapitalizeLDAPPath(request.Inputs["Parent OU LDAP Path"].AsString()); string ouDescription = string.Empty; if (request.Inputs.Contains("New OU Description")) { ouDescription = request.Inputs["New OU Description"].AsString(); } string connectionPrefix = parentLDAPPath; DirectoryEntry dirEntry = new DirectoryEntry(connectionPrefix, credentials.UserName + "@" + credentials.Domain, credentials.Password); DirectoryEntry newOU = dirEntry.Children.Add("OU=" + ouName, "OrganizationalUnit"); try { if (!ouDescription.Equals(string.Empty)) { newOU.Properties["description"].Value = ouDescription; } newOU.CommitChanges(); } catch (Exception e) { response.ReportErrorEvent("Error setting description", e.Message.ToString()); } string ouLDAPPath = newOU.Path; response.Publish("Organization Unit LDAP Path", ouLDAPPath); }
public void Execute(IActivityRequest request, IActivityResponse response) { inputString = request.Inputs["Input String"].AsString(); try { response.PublishRange(getLines()); } catch (Exception ex) { response.ReportErrorEvent("Failed to parse line", ex.ToString()); } }
public void Execute(IActivityRequest request, IActivityResponse response) { String computerName = request.Inputs["Computer Name"].AsString(); String localGroupName = request.Inputs["Local Group Name"].AsString(); String userName = request.Inputs["User Name"].AsString(); String domain = request.Inputs["Domain"].AsString(); String aUserName = String.Empty; String aUserDomain = String.Empty; String aUserPassword = String.Empty; if (request.Inputs.Contains("Alternate Connection Username")) { aUserName = request.Inputs["Alternate Connection Username"].AsString(); } if (request.Inputs.Contains("Alternate Connection User Domain")) { aUserDomain = request.Inputs["Alternate Connection User Domain"].AsString(); } if (request.Inputs.Contains("Alternate Connection Password")) { aUserPassword = request.Inputs["Alternate Connection Password"].AsString(); } try { DirectoryEntry AD; if (aUserName.Equals(String.Empty) || aUserDomain.Equals(String.Empty) || aUserPassword.Equals(String.Empty)) { AD = new DirectoryEntry("WinNT://" + computerName + ",computer"); } else { AD = new DirectoryEntry("WinNT://" + computerName + ",computer", string.Format("{0}@{1}", aUserName, aUserDomain), aUserPassword); } if (domain != null) { DirectoryEntry Domain; if (aUserName.Equals(String.Empty) || aUserDomain.Equals(String.Empty) || aUserPassword.Equals(String.Empty)) { Domain = new DirectoryEntry("WinNT://" + domain); } else { Domain = new DirectoryEntry("WinNT://" + domain, string.Format("{0}@{1}", aUserName, aUserDomain), aUserPassword); } DirectoryEntry user = Domain.Children.Find(userName, "User"); DirectoryEntry grp = AD.Children.Find(localGroupName, "group"); if (grp != null) { grp.Invoke("Remove", new object[] { user.Path.ToString() }); response.Publish("Group Name", localGroupName); response.Publish("User Name", user.Path.ToString()); } else { response.ReportErrorEvent("Failed to find local group", ""); throw new Exception("Failed to find local group"); } } else { DirectoryEntry user = AD.Children.Find(userName, "User"); DirectoryEntry grp = AD.Children.Find(localGroupName, "group"); if (grp != null) { grp.Invoke("Remove", new object[] { user.Path.ToString() }); response.Publish("Group Name", localGroupName); response.Publish("User Name", user.Path.ToString()); } else { response.ReportErrorEvent("Failed to find local group", ""); throw new Exception("Failed to find local group"); } } } catch (Exception ex) { response.ReportErrorEvent("Failed to add user to local group", ex.Message.ToString()); throw ex; } }