manifests/collectors/Compute/AvailabilitySets.psd1

#
# GENERATED by scripts/ConvertTo-ScoutCollectorDefinition.ps1 from Modules/Public/InventoryModules/Compute/AvailabilitySets.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 = @(
        'microsoft.compute/availabilitysets'
    )

    ResourceTypeMatching = 'Grouped'

    AdditionalFilter = $null

    FilterPreamble = ''

    RowLoopVariable = '1'

    Preamble = @'
$ResUCount = 1
                $sub1 = $SUB | Where-Object { $_.Id -eq $1.subscriptionId }
                $data = $1.PROPERTIES
                # `virtualMachines` is an ARRAY, and it is absent (not empty) on an availability
                # set that has never had a VM placed in it -- both shapes make the raw
                # `$data.virtualMachines.id` chain throw under StrictMode (AB#5671). -Enumerate
                # reproduces the member enumeration the original relied on, so a set WITH members
                # still yields exactly the same id (or array of ids) as before.
                $AvSetVMIds = Get-AZSCSafeProperty -InputObject $data -Path 'virtualMachines.id' -Enumerate
                $Orphaned = if([string]::IsNullOrEmpty($AvSetVMIds)){$true}else{$false}
                $Retired = $Retirements | Where-Object { $_.id -eq $1.id }
                if ($Retired)
                    {
                        $RetiredFeature = foreach ($Retire in $Retired)
                            {
                                $RetiredServiceID = $Unsupported | Where-Object {$_.Id -eq $Retired.ServiceID}
                                $tmp0 = [pscustomobject]@{
                                        'RetiredFeature' = $RetiredServiceID.RetiringFeature
                                        'RetiredDate' = $RetiredServiceID.RetirementDate
                                    }
                                $tmp0
                            }
                        $RetiringFeature = if (@($RetiredFeature.RetiredFeature).count -gt 1) { $RetiredFeature.RetiredFeature | ForEach-Object { $_ + ' ,' } }else { $RetiredFeature.RetiredFeature}
                        $RetiringFeature = [string]$RetiringFeature
                        $RetiringFeature = if ($RetiringFeature -like '* ,*') { $RetiringFeature -replace ".$" }else { $RetiringFeature }
 
                        $RetiringDate = if (@($RetiredFeature.RetiredDate).count -gt 1) { $RetiredFeature.RetiredDate | ForEach-Object { $_ + ' ,' } }else { $RetiredFeature.RetiredDate}
                        $RetiringDate = [string]$RetiringDate
                        $RetiringDate = if ($RetiringDate -like '* ,*') { $RetiringDate -replace ".$" }else { $RetiringDate }
                    }
                else
                    {
                        $RetiringFeature = $null
                        $RetiringDate = $null
                    }
                # A Resource Graph row for an untagged resource OMITS `tags` rather than carrying
                # an empty object, so the raw `$1.tags` read throws under StrictMode (AB#5671).
                # `$null.psobject.properties` throws too, so the psobject read is guarded on the
                # value as well as on the key. The '0' fall-back is retained exactly: an untagged
                # resource still emits ONE row with empty Tag Name/Value, rather than none.
                $RowTags = Get-AZSCSafeProperty -InputObject $1 -Path 'tags'
                $TagProps = if ($null -ne $RowTags) { $RowTags.psobject.properties } else { $null }
                # The historic '0' sentinel existed only to make the tag loop run once for an
                # untagged resource; `'0'.Name` throws under StrictMode, and an empty tag object
                # runs the loop once AND emits the identical [string]-cast empty Tag Name/Value.
                $Tags = if(![string]::IsNullOrEmpty($TagProps)){$TagProps}else{[pscustomobject]@{ Name = $null; Value = $null }}
'@


    AdditionalRowLoops = @(
        @{
            Variable = 'vmid'
            Source = '$AvSetVMIds'
            Preamble = '$vmIds = $vmid.split(''/'')[8]'
        }
    )

    TagLoop = @{
        Variable = 'Tag'
        Source = '$Tags'
        Preamble = ''
    }

    Fields = @(
        @{
            Name = 'ID'
            Expression = '$1.id'
        }
        @{
            Name = 'Subscription'
            Expression = '$sub1.Name'
        }
        @{
            Name = 'Resource Group'
            Expression = '$1.RESOURCEGROUP'
        }
        @{
            Name = 'Name'
            Expression = '$1.NAME'
        }
        @{
            Name = 'Location'
            Expression = '$1.LOCATION'
        }
        @{
            Name = 'Retiring Feature'
            Expression = '$RetiringFeature'
        }
        @{
            Name = 'Retiring Date'
            Expression = '$RetiringDate'
        }
        @{
            Name = 'Orphaned'
            Expression = '$Orphaned'
        }
        @{
            Name = 'Fault Domains'
            Expression = '[string]$data.platformFaultDomainCount'
        }
        @{
            Name = 'Update Domains'
            Expression = '[string]$data.platformUpdateDomainCount'
        }
        @{
            Name = 'Virtual Machines'
            Expression = '[string]$vmIds'
        }
        @{
            Name = 'Resource U'
            Expression = '$ResUCount'
        }
        @{
            Name = 'Tag Name'
            Expression = '[string]$Tag.Name'
        }
        @{
            Name = 'Tag Value'
            Expression = '[string]$Tag.Value'
        }
    )

    Export = @{
        WorksheetName = 'Availability Sets'
        TableNamePrefix = 'AvSetTable_'
        Columns = @(
            'Subscription'
            'Resource Group'
            'Name'
            'Location'
            'Retiring Feature'
            'Retiring Date'
            'Orphaned'
            'Fault Domains'
            'Update Domains'
            'Virtual Machines'
            'Resource U'
        )
        TagColumns = @(
            'Tag Name'
            'Tag Value'
        )
        TagColumnsBefore = 'Resource U'
        NumberFormat = '0'
        ConditionalText = @(
            'New-ConditionalText TRUE -Range G:G'
            'New-ConditionalText -Range E2:E100 -ConditionalType ContainsText'
        )
    }

    SourceCollector = 'Modules/Public/InventoryModules/Compute/AvailabilitySets.ps1'
}