diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs index b9e2884f..09b99f2c 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs @@ -1058,7 +1058,7 @@ namespace WebsitePanel.EnterpriseServer var accountNames = users.Select(x => x.AccountName).ToList(); //Set on server - rds.SetUsersInCollection(org.OrganizationId, collection.Name, users.Select(x => x.SamAccountName).ToArray()); + rds.SetUsersInCollection(org.OrganizationId, collection.Name, users.Select(x => x.AccountName).ToArray()); //Remove from db foreach (var userInDb in usersInDb) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs b/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs index 2c892a1a..58d9ff9f 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs @@ -527,6 +527,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices catch (Exception e) { result = false; + Log.WriteWarning(e.ToString()); } return result; @@ -672,6 +673,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices try { + Log.WriteWarning(string.Format("App alias: {0}\r\nCollection Name:{2}\r\nUsers: {1}", remoteApp.Alias, string.Join("; ", users), collectionName)); runspace = OpenRunspace(); Command cmd = new Command("Set-RDRemoteApp"); @@ -680,8 +682,18 @@ namespace WebsitePanel.Providers.RemoteDesktopServices cmd.Parameters.Add("DisplayName", remoteApp.DisplayName); cmd.Parameters.Add("UserGroups", users); cmd.Parameters.Add("Alias", remoteApp.Alias); + object[] errors; - ExecuteShellCommand(runspace, cmd, false).FirstOrDefault(); + ExecuteShellCommand(runspace, cmd, false, out errors).FirstOrDefault(); + + if (errors.Any()) + { + Log.WriteWarning(string.Format("{0} adding users errors: {1}", remoteApp.DisplayName, string.Join("\r\n", errors.Select(e => e.ToString()).ToArray()))); + } + else + { + Log.WriteWarning(string.Format("{0} users added successfully", remoteApp.DisplayName)); + } } catch(Exception) { @@ -985,15 +997,23 @@ namespace WebsitePanel.Providers.RemoteDesktopServices //adding users to group foreach (var user in users) - { - var samName = user.Split('\\').Last(); - var userPath = GetUserPath(organizationId, samName); + { + var userPath = GetUserPath(organizationId, user); + Log.WriteWarning(string.Format("User Path: {0}", userPath)); + Log.WriteWarning(string.Format("Group Name: {0}", usersGroupName)); if (ActiveDirectoryUtils.AdObjectExists(userPath)) { + var userObject = ActiveDirectoryUtils.GetADObject(userPath); + var samName = (string)ActiveDirectoryUtils.GetADObjectProperty(userObject, "sAMAccountName"); + Log.WriteWarning(string.Format("SAMAccountName: {0}", samName)); + if (!ActiveDirectoryUtils.IsUserInGroup(samName, usersGroupName)) { - ActiveDirectoryUtils.AddObjectToGroup(userPath, GetUsersGroupPath(organizationId, collectionName)); + Log.WriteWarning(string.Format("{0} not exists in {1}", samName, usersGroupName)); + var userGroupsPath = GetUsersGroupPath(organizationId, collectionName); + ActiveDirectoryUtils.AddObjectToGroup(userPath, userGroupsPath); + Log.WriteWarning(string.Format("{0} added", samName)); } } } diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditApplicationUsers.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditApplicationUsers.ascx.cs index eaa2d42f..4e792004 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditApplicationUsers.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditApplicationUsers.ascx.cs @@ -50,7 +50,7 @@ namespace WebsitePanel.Portal.RDS litCollectionName.Text = collection.Name; txtApplicationName.Text = remoteApp.DisplayName; - var remoteAppUsers = organizationUsers.Where(x => applicationUsers.Select(a => a.Split('\\').Last().ToLower()).Contains(x.SamAccountName.Split('\\').Last().ToLower())); + var remoteAppUsers = organizationUsers.Where(x => applicationUsers.Contains(x.AccountName)); users.SetUsers(remoteAppUsers.ToArray()); } @@ -64,7 +64,7 @@ namespace WebsitePanel.Portal.RDS var applications = ES.Services.RDS.GetCollectionRemoteApplications(PanelRequest.ItemID, collection.Name); var remoteApp = applications.Where(x => x.Alias.Equals(PanelRequest.ApplicationID, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault(); remoteApp.DisplayName = txtApplicationName.Text; - ES.Services.RDS.SetApplicationUsers(PanelRequest.ItemID, PanelRequest.CollectionID, remoteApp, users.GetUsers().Select(x => x.SamAccountName.Split('\\').Last()).ToArray()); + ES.Services.RDS.SetApplicationUsers(PanelRequest.ItemID, PanelRequest.CollectionID, remoteApp, users.GetUsers().Select(x => x.AccountName).ToArray()); } catch (Exception ex) {