help understanding cmdlet

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Sam Boutros Sam Boutros 9 months ago.

  • Author
    Posts
  • #55252
    Profile photo of Sam Boutros
    Sam Boutros
    Participant

    I'm looking into a cmdlet and it's unclear to me what some parts of the code trying to do. Was hoping if someone can explain:

    First there's this code block:

    [OutputType([Microsoft.Management.Infrastructure.CimInstance])]
    [OutputType('Microsoft.Management.Infrastructure.CimInstance#MSFT_HCSStorageAccountCredential_TestResult')]
    [OutputType([Microsoft.Management.Infrastructure.CimInstance])]
    [OutputType('Microsoft.Management.Infrastructure.CimInstance#MSFT_HCSStorageAccountCredential_TestResult')]
    [OutputType([Microsoft.Management.Infrastructure.CimInstance])]
    [OutputType('Microsoft.Management.Infrastructure.CimInstance#MSFT_HCSStorageAccountCredential_TestResult')]
    

    Next there's a param() block which is understandable.

    Next, there's a dynamic parameter block:

    DynamicParam {
        try {
            if (-not $__cmdletization_exceptionHasBeenThrown) {
                $__cmdletization_objectModelWrapper = Microsoft.PowerShell.Utility\New-Object $script:ObjectModelWrapper
                $__cmdletization_objectModelWrapper.Initialize($PSCmdlet, $script:ClassName, $script:ClassVersion, $script:ModuleVersion, $script:PrivateData)
    
                if ($__cmdletization_objectModelWrapper -is [System.Management.Automation.IDynamicParameters]) {
                    ([System.Management.Automation.IDynamicParameters]$__cmdletization_objectModelWrapper).GetDynamicParameters()
                }
            }
        } catch {
            $__cmdletization_exceptionHasBeenThrown = $true
            throw
        }
    }
    

    again, not clear on what's it's trying to do..
    Next, is a Begin section:

    Begin {
        $__cmdletization_exceptionHasBeenThrown = $false
        try {
            __cmdletization_BindCommonParameters $__cmdletization_objectModelWrapper $PSBoundParameters
            $__cmdletization_objectModelWrapper.BeginProcessing()
        } catch {
            $__cmdletization_exceptionHasBeenThrown = $true
            throw
        }
    }
    

    Finally, a Process section:

    Process {
        $__cmdletization_methodParameters = Microsoft.PowerShell.Utility\New-Object 'System.Collections.Generic.List[Microsoft.PowerShell.Cmdletization.MethodParameter]'
            [object]$__cmdletization_defaultValue = $null
            [object]$__cmdletization_defaultValueIsPresent = $false
            if ($PSBoundParameters.ContainsKey('Name')) {
                [object]$__cmdletization_value = ${Name}
                $__cmdletization_methodParameter = Microsoft.PowerShell.Utility\New-Object Microsoft.PowerShell.Cmdletization.MethodParameter -Property @{
                    Name = 'Name'; ParameterType = 'System.String'; Bindings = 'In'; Value = $__cmdletization_value; IsValuePresent = $true}
            } else {
                $__cmdletization_methodParameter = Microsoft.PowerShell.Utility\New-Object Microsoft.PowerShell.Cmdletization.MethodParameter -Property @{
                    Name = 'Name'; ParameterType = 'System.String'; Bindings = 'In'; Value = $__cmdletization_defaultValue; IsValuePresent = $__cmdletization_defaultValueIsPresent}
            }
            $__cmdletization_methodParameters.Add($__cmdletization_methodParameter)
    
            [object]$__cmdletization_defaultValue = $null
            [object]$__cmdletization_defaultValueIsPresent = $false
            $__cmdletization_methodParameter = Microsoft.PowerShell.Utility\New-Object Microsoft.PowerShell.Cmdletization.MethodParameter -Property @{
                Name = 'CmdletOutput'; ParameterType = 'Microsoft.Management.Infrastructure.CimInstance'; Bindings = 'Out'; Value = $__cmdletization_defaultValue; IsValuePresent = $__cmdletization_defaultValueIsPresent}
            $__cmdletization_methodParameter.ParameterTypeName = 'Microsoft.Management.Infrastructure.CimInstance#MSFT_HCSStorageAccountCredential_TestResult'
            $__cmdletization_methodParameters.Add($__cmdletization_methodParameter)
    
            $__cmdletization_returnValue = Microsoft.PowerShell.Utility\New-Object Microsoft.PowerShell.Cmdletization.MethodParameter -Property @{ 
                Name = 'ReturnValue'; ParameterType = 'System.Int32'; Bindings = 'Error'; Value = $null; IsValuePresent = $false }
    
            $__cmdletization_methodInvocationInfo = Microsoft.PowerShell.Utility\New-Object Microsoft.PowerShell.Cmdletization.MethodInvocationInfo @(
                'TestByName', $__cmdletization_methodParameters, $__cmdletization_returnValue)
          
            $__cmdletization_objectModelWrapper.ProcessRecord($__cmdletization_methodInvocationInfo)
            }
    }
    
  • #55328
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Well... knowing little about your background, I'm not sure what I can assume about your knowledge. I'm also not sure I can write you a book about what-all that's doing ;). Is there maybe a particular piece that you don't understand, that we could start with?

    • #55357
      Profile photo of Sam Boutros
      Sam Boutros
      Participant

      Hey Don, thanks for reply. I've been working with PS for about 3 years. I've from SysOps background not DevOps.
      I probably should have small specific questions. Let me try to do that 🙂

      Here is a single line of code:

      [OutputType([Microsoft.Management.Infrastructure.CimInstance])][OutputType('Microsoft.Management.Infrastructure.CimInstance#MSFT_HCSStorageAccountCredential_TestResult')]
      

      what's this one line doing?

      Thanks

You must be logged in to reply to this topic.