MegaBites-AI/Windows-powershell
0372
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4#region Using directives5 6using System;7using System.Collections.Generic;8using System.Diagnostics.CodeAnalysis;9using System.Management.Automation;10 11#endregion12 13namespace Microsoft.Management.Infrastructure.CimCmdlets14{15 /// <summary>16 /// <para>17 /// Enables the user to enumerate the list of CIM Classes under a specific18 /// Namespace. If no list of classes is given, the Cmdlet returns all19 /// classes in the given namespace.20 /// </para>21 /// <para>22 /// NOTES: The class instance contains the Namespace properties23 /// Should the class remember what Session it came from? No.24 /// </para>25 /// </summary>26 [Alias("gcls")]27 [Cmdlet(VerbsCommon.Get, GetCimClassCommand.Noun, DefaultParameterSetName = ComputerSetName, HelpUri = "https://go.microsoft.com/fwlink/?LinkId=227959")]28 [OutputType(typeof(CimClass))]29 public class GetCimClassCommand : CimBaseCommand30 {31 #region constructor32 33 /// <summary>34 /// Initializes a new instance of the <see cref="GetCimClassCommand"/> class.35 /// </summary>36 public GetCimClassCommand()37 : base(parameters, parameterSets)38 {39 DebugHelper.WriteLogEx();40 }41 42 #endregion43 44 #region parameters45 46 /// <summary>47 /// Gets or sets flag to retrieve a localized data for WMI class.48 /// </summary>49 [Parameter]50 public SwitchParameter Amended { get; set; }51 52 /// <summary>53 /// <para>54 /// The following is the definition of the input parameter "ClassName".55 /// </para>56 /// <para>57 /// Wildcard expansion should be allowed.58 /// </para>59 /// </summary>60 [Parameter(61 Position = 0,62 ValueFromPipelineByPropertyName = true)]63 public string ClassName { get; set; }64 65 /// <summary>66 /// <para>67 /// The following is the definition of the input parameter "Namespace".68 /// Specifies the Namespace under which to look for the specified class name.69 /// If no class name is specified, the cmdlet should return all classes under70 /// the specified Namespace.71 /// </para>72 /// <para>73 /// Default namespace is root\cimv274 /// </para>75 /// </summary>76 [Parameter(77 Position = 1,78 ValueFromPipelineByPropertyName = true)]79 public string Namespace { get; set; }80 81 /// <summary>82 /// The following is the definition of the input parameter "OperationTimeoutSec".83 /// Enables the user to specify the operation timeout in Seconds. This value84 /// overwrites the value specified by the CimSession Operation timeout.85 /// </summary>86 [Alias(AliasOT)]87 [Parameter(ValueFromPipelineByPropertyName = true)]88 public uint OperationTimeoutSec { get; set; }89 90 /// <summary>91 /// The following is the definition of the input parameter "Session".92 /// Uses a CimSession context.93 /// </summary>94 [Parameter(95 Mandatory = true,96 ValueFromPipeline = true,97 ParameterSetName = SessionSetName)]98 [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]99 public CimSession[] CimSession100 {101 get102 {103 return cimSession;104 }105 106 set107 {108 cimSession = value;109 base.SetParameter(value, nameCimSession);110 }111 }112 113 private CimSession[] cimSession;114 115 /// <summary>116 /// <para>The following is the definition of the input parameter "ComputerName".117 /// Provides the name of the computer from which to retrieve the <see cref="CimClass"/>118 /// </para>119 /// <para>120 /// If no ComputerName is specified the default value is "localhost"121 /// </para>122 /// </summary>123 [Alias(AliasCN, AliasServerName)]124 [Parameter(125 ValueFromPipelineByPropertyName = true,126 ParameterSetName = ComputerSetName)]127 [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]128 public string[] ComputerName129 {130 get131 {132 return computerName;133 }134 135 set136 {137 computerName = value;138 base.SetParameter(value, nameComputerName);139 }140 }141 142 private string[] computerName;143 144 /// <summary>145 /// <para>146 /// The following is the definition of the input parameter "MethodName",147 /// Which may contains wildchar.148 /// Then Filter the <see cref="CimClass"/> by given methodname149 /// </para>150 /// </summary>151 [Parameter(ValueFromPipelineByPropertyName = true)]152 public string MethodName { get; set; }153 154 /// <summary>155 /// <para>156 /// The following is the definition of the input parameter "PropertyName",157 /// Which may contains wildchar.158 /// Filter the <see cref="CimClass"/> by given property name.159 /// </para>160 /// </summary>161 [Parameter(ValueFromPipelineByPropertyName = true)]162 public string PropertyName { get; set; }163 164 /// <summary>165 /// <para>166 /// The following is the definition of the input parameter "QualifierName",167 /// Which may contains wildchar.168 /// Filter the <see cref="CimClass"/> by given methodname169 /// </para>170 /// </summary>171 [Parameter(ValueFromPipelineByPropertyName = true)]172 public string QualifierName { get; set; }173 174 #endregion175 176 #region cmdlet methods177 178 /// <summary>179 /// BeginProcessing method.180 /// </summary>181 protected override void BeginProcessing()182 {183 this.CmdletOperation = new CmdletOperationBase(this);184 this.AtBeginProcess = false;185 }186 187 /// <summary>188 /// ProcessRecord method.189 /// </summary>190 protected override void ProcessRecord()191 {192 base.CheckParameterSet();193 CimGetCimClass cimGetCimClass = this.GetOperationAgent() ?? CreateOperationAgent();194 195 cimGetCimClass.GetCimClass(this);196 cimGetCimClass.ProcessActions(this.CmdletOperation);197 }198 199 /// <summary>200 /// EndProcessing method.201 /// </summary>202 protected override void EndProcessing()203 {204 CimGetCimClass cimGetCimClass = this.GetOperationAgent();205 cimGetCimClass?.ProcessRemainActions(this.CmdletOperation);206 }207 208 #endregion209 210 #region helper methods211 212 /// <summary>213 /// <para>214 /// Get <see cref="CimNewCimInstance"/> object, which is215 /// used to delegate all New-CimInstance operations.216 /// </para>217 /// </summary>218 private CimGetCimClass GetOperationAgent()219 {220 return this.AsyncOperation as CimGetCimClass;221 }222 223 /// <summary>224 /// <para>225 /// Create <see cref="CimGetCimClass"/> object, which is226 /// used to delegate all Get-CimClass operations.227 /// </para>228 /// </summary>229 /// <returns></returns>230 private CimGetCimClass CreateOperationAgent()231 {232 CimGetCimClass cimGetCimClass = new();233 this.AsyncOperation = cimGetCimClass;234 return cimGetCimClass;235 }236 237 #endregion238 239 #region internal const strings240 241 /// <summary>242 /// Noun of current cmdlet.243 /// </summary>244 internal const string Noun = @"CimClass";245 246 #endregion247 248 #region private members249 250 #region const string of parameter names251 internal const string nameCimSession = "CimSession";252 internal const string nameComputerName = "ComputerName";253 #endregion254 255 /// <summary>256 /// Static parameter definition entries.257 /// </summary>258 private static readonly Dictionary<string, HashSet<ParameterDefinitionEntry>> parameters = new()259 {260 {261 nameCimSession, new HashSet<ParameterDefinitionEntry> {262 new ParameterDefinitionEntry(CimBaseCommand.SessionSetName, true),263 }264 },265 266 {267 nameComputerName, new HashSet<ParameterDefinitionEntry> {268 new ParameterDefinitionEntry(CimBaseCommand.ComputerSetName, false),269 }270 },271 };272 273 /// <summary>274 /// Static parameter set entries.275 /// </summary>276 private static readonly Dictionary<string, ParameterSetEntry> parameterSets = new()277 {278 { CimBaseCommand.SessionSetName, new ParameterSetEntry(1) },279 { CimBaseCommand.ComputerSetName, new ParameterSetEntry(0, true) },280 };281 #endregion282 }283}284 