internal/functions/Get-DscResourceTypeInformation.ps1
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 |
Function Get-DscResourceTypeInformation { <# .SYNOPSIS Collate the information about a DSC resource for building a Puppet resource_api type. .DESCRIPTION This function leverages the Get-DscResource command and the AST for DSC Resources implemented in PowerShell to return additional information about the DSC Resource for building a Puppet resource_api compliant Type, including retrieving help info, default values, and mandatory status. .PARAMETER DscResource The DscResourceInfo object to introspect; can be passed via the pipeline, normally retrieved via calling Get-DscResource. .PARAMETER Name If not passing a full object, specify the name of the DSC Resource to retrieve and introspect. .PARAMETER Module If not passing a full object, specify the module name of the the DSC Resource to retrieve and introspect. Can be either a string or a hash containing the keys ModuleName and ModuleVersion. .EXAMPLE Get-DscResource -Name PSRepository | Get-DscResourceTypeInformation Retrieve the information necessary for generating a Puppet Resource API type from a DSC Resource object. .EXAMPLE Get-DscResourceTypeInformation -DscResourceName PSRepository Retrieve the information necessary for generating a Puppet Resource API type by searching for a DSC resource object via Get-DscResource. Will ONLY find the resource if it is in the PSModulePath. .NOTES This function currently takes EITHER: 1. A DscResource Object, as passed by Get-DSCResource 2. A combo of name/module to retrieve DSC Resources from #> [CmdletBinding( DefaultParameterSetName='ByObject' )] Param( [Parameter( ValueFromPipeline, ParameterSetName = 'ByObject' )] [Microsoft.PowerShell.DesiredStateConfiguration.DscResourceInfo[]]$DscResource, [Parameter( ValueFromPipelineByPropertyName, ParameterSetName = 'ByProperty' )] [string[]]$Name, [Parameter( ValueFromPipelineByPropertyName, ParameterSetName = 'ByProperty' )] [object]$Module ) Begin{ $RunningElevated = Test-RunningElevated } Process { # Retrieve the DSC Resource information from the system unless passed directly If ($null -eq $DscResource) { if ($null -eq $Module) { $DscResourceToProcess = Get-DscResource -Name $Name -ErrorAction Stop } else { $DscResourceToProcess = Get-DscResource -Name $Name -Module $Module -ErrorAction Stop } } Else { $DscResourceToProcess = $DscResource } ForEach ($Resource in $DscResourceToProcess) { $Value = If ($RunningElevated -and ($DscResource.ImplementedAs -ne 'Composite')) { Get-DscResourceParameterInfoByCimClass -DscResource $Resource } Else { Get-DscResourceParameterInfo -DscResource $Resource } $Parameters = @{ MemberType = 'NoteProperty' Name = 'ParameterInfo' Value = $Value PassThru = $True } $Resource | Add-Member @Parameters } } End {} } |