locked
Does CIM Have a 'GetMethodParameters' Method Like WMI? RRS feed

  • Question

  • Via WMI I can not only see the methods available for a particular class:

    $WMIClass = [wmiclass]"\\$env:ComputerName\root\cimv2:Win32_Share"
    $WMIClass.psbase.Methods


    But I can also see the parameters required for said method by creating a valid object pre-populated with the parameters:

    $WMIParams = $WMIClass.psbase.GetMethodParameters('Create')

    What makes this especially helpful is that the resulting object keeps the details and types of each parameter:

    PS C:\> $WMIParams
    __GENUS          : 2
    __CLASS          : __PARAMETERS
    __SUPERCLASS     : 
    __DYNASTY        : __PARAMETERS
    __RELPATH        : 
    __PROPERTY_COUNT : 7
    __DERIVATION     : {}
    __SERVER         : 
    __NAMESPACE      : 
    __PATH           : 
    Access           : 
    Description      : 
    MaximumAllowed   : 
    Name             : 
    Password         : 
    Path             : 
    Type             : 
    PSComputerName   : 
    
    PS C:\> $WMIParams | gm
       TypeName: System.Management.ManagementBaseObject#\__PARAMETERS
    
    Name             MemberType    Definition                                                                   
    ----             ----------    ----------                                                                   
    PSComputerName   AliasProperty PSComputerName = __SERVER                                                    
    Access           Property      System.Management.ManagementObject#Win32_SecurityDescriptor Access {get;set;}
    Description      Property      string Description {get;set;}                                                
    MaximumAllowed   Property      uint32 MaximumAllowed {get;set;}                                             
    Name             Property      string Name {get;set;}                                                       
    Password         Property      string Password {get;set;}                                                   
    Path             Property      string Path {get;set;}                                                       
    Type             Property      uint32 Type {get;set;}                                                       
    __CLASS          Property      string __CLASS {get;set;}                                                    
    __DERIVATION     Property      string[] __DERIVATION {get;set;}                                             
    __DYNASTY        Property      string __DYNASTY {get;set;}                                                  
    __GENUS          Property      int __GENUS {get;set;}                                                       
    __NAMESPACE      Property      string __NAMESPACE {get;set;}                                                
    __PATH           Property      string __PATH {get;set;}                                                     
    __PROPERTY_COUNT Property      int __PROPERTY_COUNT {get;set;}                                              
    __RELPATH        Property      string __RELPATH {get;set;}                                                  
    __SERVER         Property      string __SERVER {get;set;}                                                   
    __SUPERCLASS     Property      string __SUPERCLASS {get;set;}   

    This is especially helpful because it allows one to easily create a valid parameter/argument object for use during invocation and would not allow someone to set $WMIParams.Access to something that wasn't a Win32_SecurityDescriptor, failing with a type mismatch error giving them a clue at population time versus invocation.

    $WMIParams.Access = [Win32_SecurityDescriptor_Object]
    $WMIParams.Description = 'New Description'
    $WMIParams.MaximumAllowed = [uint32] 10
    Invoke-WmiMethod -ComputerName $env:ComputerName -Class Win32_Share -Namespace 'root\cimv2' -Name SetShareInfo -ArgumentList $WMIParams -Verbose -ErrorAction Stop



    In my endeavor to get more comfortable with CIM I'm wondering if there is an equivalent CIM method.

    $CIMClass = Get-CimClass -ClassName Win32_Share -Namespace root\cimv2 -ComputerName $env:COMPUTERNAME
    $CIMClass.CimClassMethods
    $CimClass.CimClassMethods.Item('SetShareInfo')
    $CimParams = ??


    So far I've been doing it this way:

    $CimParams = @{
        Access = $Win32_SecurityDescriptor_Object
        Description = 'New Description'
        MaximumAllowed = [uint32] 10
    }
    Invoke-CimMethod -ComputerName $env:ComputerName -ClassName Win32_Share -Namespace 'root\cimv2' -MethodName SetShareInfo -Arguments $CimParams -Verbose

    With CIM on the other hand one is left to create their own object Hashtable System.Object and they just have to know ahead of time what type each parameter/property wants.

    This isn't a problem - just more about my level of curiosity to the 1-to-1 functionality between WMI and CIM.


    • Edited by JuliusPIV Friday, March 2, 2018 6:29 PM
    Friday, March 2, 2018 6:28 PM

Answers

  • The simple answer is "No".  You can only get the class and then get the methods from the class.

    You can get the params for a method.

    PS D:\scripts> $c = Get-CimClass -ClassName Win32_Share
    PS D:\scripts> $c.CimClassMethods |?{$_.Name -eq 'SetShareInfo'}|select -expand Parameters
    
    Name            CimType Qualifiers                                    ReferenceClassName
    ----            ------- ----------                                    ------------------
    Access         Instance {EmbeddedInstance, ID, In, MappingStrings...}
    Description      String {ID, In, MappingStrings, Optional}
    MaximumAllowed   UInt32 {ID, In, MappingStrings, Optional}


    \_(ツ)_/

    • Marked as answer by JuliusPIV Tuesday, March 6, 2018 3:59 PM
    Friday, March 2, 2018 6:49 PM

All replies

  • The simple answer is "No".  You can only get the class and then get the methods from the class.

    You can get the params for a method.

    PS D:\scripts> $c = Get-CimClass -ClassName Win32_Share
    PS D:\scripts> $c.CimClassMethods |?{$_.Name -eq 'SetShareInfo'}|select -expand Parameters
    
    Name            CimType Qualifiers                                    ReferenceClassName
    ----            ------- ----------                                    ------------------
    Access         Instance {EmbeddedInstance, ID, In, MappingStrings...}
    Description      String {ID, In, MappingStrings, Optional}
    MaximumAllowed   UInt32 {ID, In, MappingStrings, Optional}


    \_(ツ)_/

    • Marked as answer by JuliusPIV Tuesday, March 6, 2018 3:59 PM
    Friday, March 2, 2018 6:49 PM
  • Not sure if we're talking about the same thing, but Get-CimInstance has tab completion support with -ClassName.  And if you run a method without any parentheses or arguments, it will give the overload definitions.

    Friday, March 2, 2018 7:43 PM
  • Autocomplete does not include instance methods or arguments.

    Post in  UserVoice to have this added to PS.


    \_(ツ)_/

    Friday, March 2, 2018 7:48 PM