manifests/collectors/Management/PolicyDefinitions.psd1

#
# GENERATED by scripts/ConvertTo-ScoutCollectorDefinition.ps1 from Modules/Public/InventoryModules/Management/PolicyDefinitions.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/PolicyDefinition'
    )

    ResourceTypeMatching = 'Grouped'

    AdditionalFilter = $null

    FilterPreamble = ''

    RowLoopVariable = 'policy'

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

    }

    Preamble = @'
$ResUCount = 1
 
                # AB#5671. Two separate things are going on here, and only the first is in scope.
                #
                # 1. StrictMode: `$policy.Properties` is an ABSENT member, not a $null one, so the
                # read itself throws. Every read below is made safe.
                #
                # 2. A REAL, PRE-EXISTING DEFECT this exposed, deliberately NOT fixed here: as of
                # Az.Resources 7 the object Get-AzPolicyDefinition returns is FLATTENED. There is
                # no `Properties` sub-object at all (DisplayName, Mode, PolicyType, Metadata and
                # PolicyRule sit directly on the object), `Parameters` was renamed `Parameter`,
                # and `PolicyDefinitionId` / `ManagementGroupName` / `SubscriptionId` are gone --
                # `Id` replaces the first. So on any modern Az this collector already emitted a
                # row per policy with almost every column EMPTY, quietly, before StrictMode was
                # ever involved. Reading through the safe accessor keeps that output byte for
                # byte identical; re-pointing the reads at the flattened shape would change every
                # emitted value, which is a behaviour change and belongs in its own work item.
                $props = Get-AZSCSafeProperty -InputObject $policy -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' }
 
                # Parse policy rule effect
                $effect = Get-AZSCSafeProperty -InputObject $props -Path 'PolicyRule.then.effect'
                if (-not $effect) { $effect = 'Unknown' }
'@


    AdditionalRowLoops = @()

    TagLoop = $null

    Fields = @(
        @{
            Name = 'ID'
            Expression = '(Get-AZSCSafeProperty -InputObject $policy -Path ''PolicyDefinitionId'')'
        }
        @{
            Name = 'Name'
            Expression = '(Get-AZSCSafeProperty -InputObject $policy -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 = 'Mode'
            Expression = '(Get-AZSCSafeProperty -InputObject $props -Path ''Mode'')'
        }
        @{
            Name = 'Category'
            Expression = '$category'
        }
        @{
            Name = 'Version'
            Expression = '$version'
        }
        @{
            Name = 'Effect'
            Expression = '$effect'
        }
        @{
            Name = 'Parameters'
            Expression = '$params'
        }
        @{
            Name = 'Management Group'
            Expression = '(Get-AZSCSafeProperty -InputObject $policy -Path ''ManagementGroupName'')'
        }
        @{
            Name = 'Subscription'
            Expression = '(Get-AZSCSafeProperty -InputObject $policy -Path ''SubscriptionId'')'
        }
        @{
            Name = 'Resource U'
            Expression = '$ResUCount'
        }
    )

    Export = @{
        WorksheetName = 'Policy Definitions'
        TableNamePrefix = 'PolicyDefsTable_'
        Columns = @(
            'Name'
            'Display Name'
            'Description'
            'Policy Type'
            'Mode'
            'Category'
            'Version'
            'Effect'
            'Parameters'
            'Management Group'
            'Subscription'
            'Resource U'
        )
        TagColumns = @()
        TagColumnsBefore = $null
        NumberFormat = '0'
        ConditionalText = @()
    }

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