manifests/collectors/Networking/NetworkInterface.psd1

#
# GENERATED by scripts/ConvertTo-ScoutCollectorDefinition.ps1 from Modules/Public/InventoryModules/Networking/NetworkInterface.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.network/networkinterfaces'
    )

    ResourceTypeMatching = 'Grouped'

    AdditionalFilter = $null

    FilterPreamble = ''

    RowLoopVariable = '1'

    SetupPreamble = @'
$nic = $Resources | Where-Object {$_.TYPE -eq 'microsoft.network/networkinterfaces'}
    $PublicIP = $Resources | Where-Object { $_.TYPE -eq 'microsoft.network/publicipaddresses' }
'@


    SetupVariables = @(
        'nic'
        'PublicIP'
    )

    Preamble = @'
$ResUCount = 1
                    # An EMPTY $sub1 is not $null -- the match is empty for any resource whose subscription
                    # is outside the requested scope -- and reading .Name off an empty collection throws
                    # under StrictMode (AB#5671). Resolved once here, as VirtualMachine.ps1 already does.
                    $sub1 = $SUB | Where-Object { $_.Id -eq $1.subscriptionId }
                    # The else arm is $null, NOT '': with StrictMode off $sub1.Name on an unmatched ($null)
                    # $sub1 evaluated to $null, and the ~110 collectors that still read $sub1.Name directly
                    # emit $null here. '' was a silent behaviour change -- the declarative equivalence proof
                    # caught it on 11 collectors, and it would have been invisible on the rest (AB#5659).
                    $SubscriptionName = if ($sub1) { @($sub1)[0].Name } else { $null }
                    $data = $1.PROPERTIES
                    $Retired = Foreach ($Retirement in $Retirements)
                        {
                            if ($Retirement.id -eq $1.id) { $Retirement }
                        }
                    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
                        }
 
                    if(![string]::IsNullOrEmpty((Get-AZSCSafeProperty -InputObject $data -Path 'virtualmachine.id' -Enumerate)))
                        {
                            $ResourceType = 'Virtual Machine'
                            $Resource = (Get-AZSCIdSegment -Id (Get-AZSCSafeProperty -InputObject $data -Path 'virtualmachine.id' -Enumerate) -Index 8)
                        }
                    elseif(![string]::IsNullOrEmpty((Get-AZSCSafeProperty -InputObject $data -Path 'privateendpoint.id' -Enumerate)))
                        {
                            $ResourceType = 'Private Endpoint'
                            $Resource = (Get-AZSCIdSegment -Id (Get-AZSCSafeProperty -InputObject $data -Path 'privateendpoint.id' -Enumerate) -Index 8)
                        }
                    else
                        {
                            $ResourceType = 'Underutilized'
                            $Resource = 'None'
                        }
                     
                    $NSG = if(![string]::IsNullOrEmpty((Get-AZSCSafeProperty -InputObject $data -Path 'networksecuritygroup.id' -Enumerate))){(Get-AZSCIdSegment -Id (Get-AZSCSafeProperty -InputObject $data -Path 'networksecuritygroup.id' -Enumerate) -Index 8)}else{$null}
 
                    $DNS = if (@((Get-AZSCSafeProperty -InputObject $data -Path 'dnssettings.dnsservers' -Enumerate)).count -gt 1) { (Get-AZSCSafeProperty -InputObject $data -Path 'dnssettings.dnsservers' -Enumerate) | ForEach-Object { $_ + ' ,' } }else { (Get-AZSCSafeProperty -InputObject $data -Path 'dnssettings.dnsservers' -Enumerate) }
                    $DNS = [string]$DNS
                    $DNS = if ($DNS -like '* ,*') { $DNS -replace ".$" }else { $DNS }
 
                    $AcceleratedNetworking = if((Get-AZSCSafeProperty -InputObject $data -Path 'enableacceleratednetworking' -Enumerate) -eq $true){'On'}else{'Off'}
 
                    # AB#5671: an untagged resource's Resource Graph row OMITS the tags property rather
                    # than carrying an empty object, so the raw read throws under StrictMode -- and so
                    # does psobject.properties on a $null. The historic '0' sentinel existed only to make
                    # the tag loop below run ONCE for an untagged resource, but '0'.Name throws too; an
                    # empty tag object runs it once AND emits the identical [string]-cast empty Name/Value.
                    $RowTags = Get-AZSCSafeProperty -InputObject $1 -Path 'tags'
                    $TagProps = if ($null -ne $RowTags) { $RowTags.psobject.properties } else { $null }
                    $Tags = if (![string]::IsNullOrEmpty($TagProps)) { $TagProps } else { [pscustomobject]@{ Name = $null; Value = $null } }
'@


    AdditionalRowLoops = @(
        @{
            Variable = '2'
            Source = '(Get-AZSCSafeProperty -InputObject $data -Path ''ipconfigurations'' -Enumerate)'
            Preamble = @'
$VNET = if(![string]::IsNullOrEmpty((Get-AZSCSafeProperty -InputObject $2 -Path 'properties.subnet.id' -Enumerate))){(Get-AZSCIdSegment -Id (Get-AZSCSafeProperty -InputObject $2 -Path 'properties.subnet.id' -Enumerate) -Index 8)}else{$null}
                            $Subnet = if(![string]::IsNullOrEmpty((Get-AZSCSafeProperty -InputObject $2 -Path 'properties.subnet.id' -Enumerate))){(Get-AZSCIdSegment -Id (Get-AZSCSafeProperty -InputObject $2 -Path 'properties.subnet.id' -Enumerate) -Index 10)}else{$null}
                            $PIP = $PublicIP | Where-Object {$_.id -eq (Get-AZSCSafeProperty -InputObject $2 -Path 'properties.publicipaddress.id' -Enumerate)}
                            $PIPName = (Get-AZSCSafeProperty -InputObject $PIP -Path 'Name' -Enumerate)
                            $PIPAddress = if(![string]::IsNullOrEmpty((Get-AZSCSafeProperty -InputObject $PIP -Path 'properties.ipaddress' -Enumerate))){(Get-AZSCSafeProperty -InputObject $PIP -Path 'properties.ipaddress' -Enumerate)}else{'Unassigned'}
'@

        }
    )

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

    Fields = @(
        @{
            Name = 'ID'
            Expression = '$1.id'
        }
        @{
            Name = 'Subscription'
            Expression = '$SubscriptionName'
        }
        @{
            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 = 'Attached Resource Type'
            Expression = '$ResourceType'
        }
        @{
            Name = 'Attached Resource'
            Expression = '$Resource'
        }
        @{
            Name = 'Network Security Group'
            Expression = '$NSG'
        }
        @{
            Name = 'DNS Servers'
            Expression = '$DNS'
        }
        @{
            Name = 'Internal Domain Suffix'
            Expression = '(Get-AZSCSafeProperty -InputObject $data -Path ''dnssettings.internaldomainnamesuffix'' -Enumerate)'
        }
        @{
            Name = 'Accelerated Networking'
            Expression = '$AcceleratedNetworking'
        }
        @{
            Name = 'IP Forwarding'
            Expression = '(Get-AZSCSafeProperty -InputObject $data -Path ''enableipforwarding'' -Enumerate)'
        }
        @{
            Name = 'MAC Address'
            Expression = '(Get-AZSCSafeProperty -InputObject $data -Path ''macaddress'' -Enumerate)'
        }
        @{
            Name = 'IP Configurations'
            Expression = '(Get-AZSCSafeProperty -InputObject $2 -Path ''name'' -Enumerate)'
        }
        @{
            Name = 'Virtual Network'
            Expression = '$VNET'
        }
        @{
            Name = 'Subnet'
            Expression = '$Subnet'
        }
        @{
            Name = 'Primary'
            Expression = '(Get-AZSCSafeProperty -InputObject $2 -Path ''properties.primary'' -Enumerate)'
        }
        @{
            Name = 'Private IP Version'
            Expression = '(Get-AZSCSafeProperty -InputObject $2 -Path ''properties.privateipaddressversion'' -Enumerate)'
        }
        @{
            Name = 'Private IP'
            Expression = '(Get-AZSCSafeProperty -InputObject $2 -Path ''properties.privateipaddress'' -Enumerate)'
        }
        @{
            Name = 'Private IP Method'
            Expression = '(Get-AZSCSafeProperty -InputObject $2 -Path ''properties.privateipallocationmethod'' -Enumerate)'
        }
        @{
            Name = 'Public IP Name'
            Expression = '$PIPName'
        }
        @{
            Name = 'Public IP'
            Expression = '$PIPAddress'
        }
        @{
            Name = 'Resource U'
            Expression = '$ResUCount'
        }
        @{
            Name = 'Tag Name'
            Expression = '[string]$Tag.Name'
        }
        @{
            Name = 'Tag Value'
            Expression = '[string]$Tag.Value'
        }
    )

    Export = @{
        WorksheetName = 'Network Interface'
        TableNamePrefix = 'NICTable_'
        Columns = @(
            'Subscription'
            'Resource Group'
            'Name'
            'Location'
            'Retiring Feature'
            'Retiring Date'
            'Attached Resource Type'
            'Attached Resource'
            'Network Security Group'
            'DNS Servers'
            'Internal Domain Suffix'
            'Accelerated Networking'
            'IP Forwarding'
            'MAC Address'
            'IP Configurations'
            'Virtual Network'
            'Subnet'
            'Primary'
            'Private IP Version'
            'Private IP'
            'Private IP Method'
            'Public IP Name'
            'Public IP'
            'Resource U'
        )
        TagColumns = @(
            'Tag Name'
            'Tag Value'
        )
        TagColumnsBefore = 'Resource U'
        NumberFormat = '0'
        ConditionalText = @(
            'New-ConditionalText Off -Range L:L'
            'New-ConditionalText Underutilized -Range G:G'
            'New-ConditionalText -Range E2:E100 -ConditionalType ContainsText'
        )
    }

    SourceCollector = 'Modules/Public/InventoryModules/Networking/NetworkInterface.ps1'
}