Beispiel #1
0
        internal List<RdsUserSession> GetRdsUserSessionsInternal(string collectionName, Runspace runSpace)
        {
            var result = new List<RdsUserSession>();
            var scripts = new List<string>();
            scripts.Add(string.Format("Get-RDUserSession -ConnectionBroker {0} - CollectionName {1} | ft CollectionName, Username, UnifiedSessionId, SessionState, HostServer", ConnectionBroker, collectionName));            
            object[] errors;
            Command cmd = new Command("Get-RDUserSession");
            cmd.Parameters.Add("CollectionName", collectionName);
            cmd.Parameters.Add("ConnectionBroker", ConnectionBroker);
            var userSessions = ExecuteShellCommand(runSpace, cmd, false, out errors);            
            var properties = typeof(RdsUserSession).GetProperties();            

            foreach(var userSession in  userSessions)
            {
                var session = new RdsUserSession
                {
                    CollectionName = GetPSObjectProperty(userSession, "CollectionName").ToString(),
                    DomainName = GetPSObjectProperty(userSession, "DomainName").ToString(),
                    HostServer = GetPSObjectProperty(userSession, "HostServer").ToString(),
                    SessionState = GetPSObjectProperty(userSession, "SessionState").ToString(),
                    UnifiedSessionId = GetPSObjectProperty(userSession, "UnifiedSessionId").ToString(),
                    SamAccountName = GetPSObjectProperty(userSession, "UserName").ToString(),
                };                                
                                
                session.IsVip = false;
                session.UserName = GetUserFullName(session.DomainName, session.SamAccountName, runSpace);
                result.Add(session);
            }

            return result;
        }
        internal List<RdsUserSession> GetRdsUserSessionsInternal(string collectionName, Runspace runSpace)
        {
            var result = new List<RdsUserSession>();
            var scripts = new List<string>();
            scripts.Add(string.Format("Get-RDUserSession -ConnectionBroker {0} - CollectionName {1} | ft CollectionName, Username, UnifiedSessionId, SessionState, HostServer", ConnectionBroker, collectionName));            
            object[] errors;
            Command cmd = new Command("Get-RDUserSession");
            cmd.Parameters.Add("CollectionName", collectionName);
            cmd.Parameters.Add("ConnectionBroker", ConnectionBroker);
            var userSessions = runSpace.ExecuteShellCommand(cmd, false, PrimaryDomainController, out errors);            
            var properties = typeof(RdsUserSession).GetProperties();            

            foreach(var userSession in  userSessions)
            {
                object collectionNameObj = RdsRunspaceExtensions.GetPSObjectProperty(userSession, "CollectionName");
                object domainName = RdsRunspaceExtensions.GetPSObjectProperty(userSession, "DomainName");
                object hostServer = RdsRunspaceExtensions.GetPSObjectProperty(userSession, "HostServer");
                object sessionState = RdsRunspaceExtensions.GetPSObjectProperty(userSession, "SessionState");
                object unifiedSessionId = RdsRunspaceExtensions.GetPSObjectProperty(userSession, "UnifiedSessionId");
                object samAccountName = RdsRunspaceExtensions.GetPSObjectProperty(userSession, "UserName");

                var session = new RdsUserSession
                {
                    CollectionName = collectionNameObj != null ? collectionNameObj.ToString() : "",
                    DomainName = domainName != null ? domainName.ToString() : "",
                    HostServer = hostServer != null ? hostServer.ToString() : "",
                    SessionState = sessionState != null ? sessionState.ToString() : "",
                    UnifiedSessionId = unifiedSessionId != null ? unifiedSessionId.ToString() : "",
                    SamAccountName = samAccountName != null ? samAccountName.ToString() : ""
                };                                
                                
                session.IsVip = false;
                session.UserName = GetUserFullName(session.DomainName, session.SamAccountName, runSpace);
                result.Add(session);
            }

            return result;
        }