Beispiel #1
0
        public void Execute(IActivityRequest request, IActivityResponse response)
        {
            SecureString password = new SecureString();

            settings.Password.ToCharArray().ToList().ForEach(password.AppendChar);
            PSCredential creds = new PSCredential(settings.UserName, password);

            PSRunspaceCreationData creationData = new PSRunspaceCreationData();

            creationData.Credentials        = creds;
            creationData.Hostname           = request.Inputs["Computer name"].AsString();
            creationData.Port               = request.Inputs["Connection port"].AsInt32();
            creationData.UseSsl             = request.Inputs["Use SSL"].AsBoolean();
            creationData.LoadMachineProfile = request.Inputs["Load host profile"].AsBoolean();
            creationData.Name               = request.Inputs["Session name"].AsString().ToUpper();

            IRunspaceManager      runspaceManager = PSRunspaceManger.CreateClient();
            RemoteOperationResult result          = runspaceManager.OpenRunspace(creationData);

            if (!result.Success)
            {
                throw new Exception(result.Message);
            }

            response.Publish("Session name", creationData.Name);
        }
Beispiel #2
0
        public void Execute(IActivityRequest request, IActivityResponse response)
        {
            IRunspaceManager      runspaceManager = PSRunspaceManger.CreateClient();
            RemoteOperationResult result          = runspaceManager.CloseRunspace(request.Inputs["Session name"].AsString().ToUpper());

            if (!result.Success)
            {
                throw new Exception(result.Message);
            }
        }
Beispiel #3
0
        public void Execute(IActivityRequest request, IActivityResponse response)
        {
            IRunspaceManager      runspaceManager = PSRunspaceManger.CreateClient();
            RemoteOperationResult result          = runspaceManager.ExecuteCommand(request.Inputs["Session name"].AsString().ToUpper(), request.Inputs["Script code"].AsString());

            if (!result.Success)
            {
                throw new Exception(result.Message);
            }

            response.Publish("Session name", request.Inputs["Session name"].AsString().ToUpper());
            response.Publish("Script result", result.Message);
        }
        public void Execute(IActivityRequest request, IActivityResponse response)
        {
            string                command         = string.Format("Set-Variable {0} \"{1}\" ", request.Inputs["Variable name"].AsString(), request.Inputs["Variable value"].AsString());
            IRunspaceManager      runspaceManager = PSRunspaceManger.CreateClient();
            RemoteOperationResult result          = runspaceManager.ExecuteCommand(request.Inputs["Session name"].AsString().ToUpper(), command);

            if (!result.Success)
            {
                throw new Exception(result.Message);
            }

            response.Publish("Session name", request.Inputs["Session Name"].AsString().ToUpper());
            response.Publish("Variable value", result.Message);
        }
Beispiel #5
0
        public void Execute(IActivityRequest request, IActivityResponse response)
        {
            try
            {
                IRunspaceManager            runspaceManager = PSRunspaceManger.CreateClient();
                Dictionary <string, string> result          = runspaceManager.GetRunspaces();

                List <SessionInfoData> sessions = new List <SessionInfoData>();
                foreach (KeyValuePair <string, string> pair in result)
                {
                    sessions.Add(new SessionInfoData(pair.Key, pair.Value));
                }

                response.WithFiltering().PublishRange(sessions);
                response.Publish("Session count", sessions.Count);
            }
            catch (Exception)
            {
                throw new Exception("An error occured while enumerating sessions");
            }
        }