Src/Session.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.IO;
using System.Xml;
using System.Reflection;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Management.Automation;
using Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.Common;
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement.Subscriptions;
using Microsoft.EnterpriseManagement.Configuration.IO;
using System.Text.RegularExpressions;

namespace SMLets
{   
    [Cmdlet(VerbsCommon.Get, "SCSMWhoAmI")]
    public class GetSCSMWhoAmICommand : ObjectCmdletHelper
    {
        private SwitchParameter _raw;
        [Parameter]
        public SwitchParameter Raw
        {
            get { return _raw; }
            set { _raw = value; }
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            string userName = _mg.GetUserName();
            if (Raw)
            {
                WriteObject(userName);
            }
            else
            {
                WriteObject(UserHelper.GetUserObjectFromString(_mg, userName, this));
            }
        }
    }

    [Cmdlet(VerbsCommon.Get, "SCSMConnectedUser")]
    public class GetSCSMConnectedUserCommand : ObjectCmdletHelper
    {
        private SwitchParameter _raw;
        [Parameter]
        public SwitchParameter Raw
        {
            get { return _raw; }
            set { _raw = value; }
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            foreach (string s in _mg.GetConnectedUserNames())
            {
                if (Raw)
                {
                    WriteObject(s);
                }
                else
                {
                    WriteObject(UserHelper.GetUserObjectFromString(_mg, s, this));
                }
            }
        }
    }

    #region SCSMSession cmdlets

    [Cmdlet("New","SCSMSession")]
    public class NewSCSMSession : SMCmdletBase
    {
        private SwitchParameter _passthru;
        [Parameter]
        public SwitchParameter PassThru
        {
            get { return _passthru; }
            set { _passthru = value; }
        }
        protected override void ProcessRecord()
        {
            if ( PassThru ) { WriteObject(_mg); }
        }
    }
    
    [Cmdlet("Get","SCSMSession")]
    public class GetSCSMSession : PSCmdlet
    {
        private string _computerName = ".*";
        [Parameter(Position=0,ValueFromPipeline=true)]
        public string ComputerName
        {
            get { return _computerName; }
            set { _computerName = value; }
        }
        private List<string> l = null;
        protected override void ProcessRecord()
        {
            l = ConnectionHelper.GetMGList(ComputerName);
            foreach(string n in l) 
            {
                WriteObject(ConnectionHelper.GetMG(n));
            }
        }
    }
    
    [Cmdlet("Remove","SCSMSession")]
    public class RemoveSCSMSession : PSCmdlet
    {
        private EnterpriseManagementGroup _emg;
        [Parameter(Mandatory=true,ValueFromPipeline=true,Position=0)]
        public EnterpriseManagementGroup EMG
        {
            get { return _emg; }
            set { _emg = value; }
        }
        protected override void ProcessRecord()
        {
            ConnectionHelper.RemoveMG(EMG.ConnectionSettings.ServerName);
        }
    }
    
    #endregion
}