iainbrighton / PScribo

PowerShell documentation framework
MIT License
231 stars 35 forks source link

Unexpected Object [system.int32] in section warning #56

Closed jbruett closed 7 years ago

jbruett commented 7 years ago

This code:

Section -Name 'Elastic IPs' -Style Heading4 {
    foreach ($vpc in $vpcs.where( {$_.region -eq $region})) {
        if ($vpc.tags.count -gt 0) {
            $namefound = $false
            foreach ($tag in $vpc.Tags) {
                if (-not $namefound) {
                    if ($tag.key -eq 'Name' -and ($tag.value -ne [string]::empty -or $tag.value -ne '')) {
                        $VpcName = $tag.value
                        $namefound = $true
                    }
                    else {
                        $VpcName = "{0}" -f ($culture.ToUpper('untagged vpc'))
                    }
                }
            }
        }
        elseif ($vpc.IsDefault) {
            $VpcName = "{0}" -f $Culture.ToTitleCase("default")
        }
        else {
            $VpcName = "{0}" -f $Culture.ToUpper("untagged vpc")
        }
        Section -Name ("{0} ({1}) EIPs" -f $VpcName, $Culture.tolower($vpc.vpcid)) -Style Heading5 {

            [system.collections.arraylist]$eipsOut = @()
            $eips = Invoke-Command -scriptblock { aws ec2 describe-addresses --profile $ProfileName --region $region } | ConvertFrom-Json
            $empty = [string]::Empty
            foreach ($eip in $eips.addresses) {
                if (-not [bool]($eip.psobject.properties.name -match 'PublicIp')) {
                    $eip | add-member -MemberType NoteProperty -Name PublicIp -Value $empty
                }
                if (-not [bool]($eip.psobject.properties.name -match 'instanceid')) {
                    $eip | add-member -MemberType NoteProperty -Name instanceid -Value $empty
                }
                if (-not [bool]($eip.psobject.properties.name -match 'allocationid')) {
                    $eip | add-member -MemberType NoteProperty -Name allocationid -Value $empty
                }
                if (-not [bool]($eip.psobject.properties.name -match 'associationid')) {
                    $eip | add-member -MemberType NoteProperty -Name associationid -Value $empty
                }
                if (-not [bool]($eip.psobject.properties.name -match 'domain')) {
                    $eip | add-member -MemberType NoteProperty -Name domain -Value $empty
                }
                if (-not [bool]($eip.psobject.properties.name -match 'networkinterfaceid')) {
                    $eip | add-member -MemberType NoteProperty -Name networkinterfaceid -Value $empty
                }
                if (-not [bool]($eip.psobject.properties.name -match 'networkinterfaceownerid')) {
                    $eip | add-member -MemberType NoteProperty -Name networkinterfaceownerid -Value $empty
                }
                if (-not [bool]($eip.psobject.properties.name -match 'privateipaddress')) {
                    $eip | add-member -MemberType NoteProperty -Name privateipaddress -Value $empty
                }
                $eipsOut.add($eip)
            }
            $eipsOut | Table -Name eips -Columns PublicIp, AllocationId, NetworkInterfaceID, AssociationId, PrivateIpAddress, Domain -Headers 'Public IP', 'Alloc. ID', 'Interface ID', 'Assoc. ID', 'Private IP', 'Domain'
        }
    }
} # End EIP

is presenting this error: WARNING: [ 11:52:14:424 ] [ Document ] - Unexpected object 'System.Int32' in section 'sharedservices-dmz-vpc EIPs'.

Running PScribo 0.7.17.75

iainbrighton commented 7 years ago

@jbruett You'll get that when something is returned to pipeline that PScribo isn't expecting. I think you might need to change the $eipOut.add($eip) line to $null = $eipOut.add($eip).

When you add an item to an ArrayList it returns the number of items in the array (your extraneous [System.Int32] 😉).

jbruett commented 7 years ago

That was it...I'd been bitten by this before and forgot about the output issue. Thanks Iain