File size: 1,693 Bytes
8c763fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Linq;
using System.Management.Automation;

namespace Microsoft.PowerShell.Commands
{
    /// <summary>
    /// A cmdlet that gets the TraceSource instances that are instantiated in the process.
    /// </summary>
    [Cmdlet(VerbsCommon.Get, "TraceSource", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=2096707")]
    [OutputType(typeof(PSTraceSource))]
    public class GetTraceSourceCommand : TraceCommandBase
    {
        #region Parameters

        /// <summary>
        /// Gets or sets the category parameter which determines which trace switch to get.
        /// </summary>
        /// <value></value>
        [Parameter(Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
        [ValidateNotNullOrEmpty()]
        public string[] Name
        {
            get
            {
                return _names;
            }

            set
            {
                if (value == null || value.Length == 0)
                {
                    value = new string[] { "*" };
                }

                _names = value;
            }
        }

        private string[] _names = new string[] { "*" };

        #endregion Parameters

        #region Cmdlet code

        /// <summary>
        /// Gets the PSTraceSource for the specified category.
        /// </summary>
        protected override void ProcessRecord()
        {
            var sources = GetMatchingTraceSource(_names, true);
            var result = sources.OrderBy(static source => source.Name);
            WriteObject(result, true);
        }

        #endregion Cmdlet code
    }
}