manifests/collectors/Management/PolicySetDefinitions.psd1

#
# GENERATED by scripts/ConvertTo-ScoutCollectorDefinition.ps1 from Modules/Public/InventoryModules/Management/PolicySetDefinitions.ps1 (AB#5660).
# Field expressions are copied verbatim from the original collector and evaluate in an
# equivalent scope -- see docs/design/decisions/declarative-collectors.md.
# Review before trusting; regenerate rather than hand-patch if the source collector changes.
#
@{
    ResourceTypes = @(
        'AZSC/Management/PolicySetDefinition'
    )

    ResourceTypeMatching = 'Grouped'

    AdditionalFilter = $null

    FilterPreamble = ''

    RowLoopVariable = 'policySet'

    RowSource = @{
        Expression = @'
foreach ($envelope in @($Resources | Where-Object { $_.TYPE -eq 'AZSC/Management/PolicySetDefinition' })) {
            @($envelope.PROPERTIES)
        }
'@

    }

    Preamble = @'
$ResUCount = 1
 
                # AB#5671, and the same two-part story as PolicyDefinitions.ps1: the StrictMode fault
                # is that `Properties` is an ABSENT member (an absent member throws, a $null one does
                # not), and the reason it is absent is that Az.Resources 7+ returns a FLATTENED
                # policy set definition -- no `Properties` sub-object, `Parameter` not `Parameters`,
                # and `Id` in place of `PolicySetDefinitionId`. That second part is a real,
                # pre-existing defect (this collector already emitted mostly-empty rows on any modern
                # Az, silently) and is deliberately NOT fixed here: re-pointing the reads at the
                # flattened shape would change every emitted value. Safe reads only.
                $props = Get-AZSCSafeProperty -InputObject $policySet -Path 'Properties'
 
                # Parse parameters
                $paramsBlock = Get-AZSCSafeProperty -InputObject $props -Path 'Parameters'
                $params = if ($paramsBlock) {
                    ($paramsBlock.PSObject.Properties | ForEach-Object { "$($_.Name) ($(Get-AZSCSafeProperty -InputObject $_.Value -Path 'type'))" }) -join '; '
                } else { 'None' }
 
                # Parse metadata
                $category = Get-AZSCSafeProperty -InputObject $props -Path 'Metadata.category'
                $version = Get-AZSCSafeProperty -InputObject $props -Path 'Metadata.version'
                if (-not $category) { $category = 'Uncategorized' }
                if (-not $version) { $version = 'N/A' }
 
                # Count policy definitions in the initiative
                $policyDefinitionRefs = Get-AZSCSafeProperty -InputObject $props -Path 'PolicyDefinitions'
                $policyCount = if ($policyDefinitionRefs) { @($policyDefinitionRefs).Count } else { 0 }
 
                # Get list of policy definition references
                $policyRefs = if ($policyDefinitionRefs) {
                    (@($policyDefinitionRefs) | ForEach-Object {
                        $refId = (Get-AZSCSafeProperty -InputObject $_ -Path 'policyDefinitionId') -split '/' | Select-Object -Last 1
                        $refId
                    }) -join '; '
                } else { 'None' }
 
                # Parse policy groups
                $policyGroups = Get-AZSCSafeProperty -InputObject $props -Path 'PolicyDefinitionGroups'
                $groupCount = if ($policyGroups) { @($policyGroups).Count } else { 0 }
'@


    AdditionalRowLoops = @()

    TagLoop = $null

    Fields = @(
        @{
            Name = 'ID'
            Expression = '(Get-AZSCSafeProperty -InputObject $policySet -Path ''PolicySetDefinitionId'')'
        }
        @{
            Name = 'Name'
            Expression = '(Get-AZSCSafeProperty -InputObject $policySet -Path ''Name'')'
        }
        @{
            Name = 'Display Name'
            Expression = '(Get-AZSCSafeProperty -InputObject $props -Path ''DisplayName'')'
        }
        @{
            Name = 'Description'
            Expression = '(Get-AZSCSafeProperty -InputObject $props -Path ''Description'')'
        }
        @{
            Name = 'Policy Type'
            Expression = '(Get-AZSCSafeProperty -InputObject $props -Path ''PolicyType'')'
        }
        @{
            Name = 'Category'
            Expression = '$category'
        }
        @{
            Name = 'Version'
            Expression = '$version'
        }
        @{
            Name = 'Policy Count'
            Expression = '$policyCount'
        }
        @{
            Name = 'Policy Definition Groups'
            Expression = '$groupCount'
        }
        @{
            Name = 'Policy References'
            Expression = '$policyRefs'
        }
        @{
            Name = 'Parameters'
            Expression = '$params'
        }
        @{
            Name = 'Management Group'
            Expression = '(Get-AZSCSafeProperty -InputObject $policySet -Path ''ManagementGroupName'')'
        }
        @{
            Name = 'Subscription'
            Expression = '(Get-AZSCSafeProperty -InputObject $policySet -Path ''SubscriptionId'')'
        }
        @{
            Name = 'Resource U'
            Expression = '$ResUCount'
        }
    )

    Export = @{
        WorksheetName = 'Policy Initiatives'
        TableNamePrefix = 'PolicyInitTable_'
        Columns = @(
            'Name'
            'Display Name'
            'Description'
            'Policy Type'
            'Category'
            'Version'
            'Policy Count'
            'Policy Definition Groups'
            'Policy References'
            'Parameters'
            'Management Group'
            'Subscription'
            'Resource U'
        )
        TagColumns = @()
        TagColumnsBefore = $null
        NumberFormat = '0'
        ConditionalText = @()
    }

    SourceCollector = 'Modules/Public/InventoryModules/Management/PolicySetDefinitions.ps1'
}