Private/Format-RyverV1FileObject.ps1

function Format-RyverV1FileObject {
    <#
    .SYNOPSIS
        Parse output from search.messages.
 
    .DESCRIPTION
        Parse output from search.messages.
 
    .INPUTS
        System.Management.Automation.PSCustomObject[]
 
    .INPUTS
        System.Management.Automation.PSCustomObject
 
    .NOTES
        - Troy Lindsay
        - Twitter: @troylindsay42
        - GitHub: tlindsay42
 
    .EXAMPLE
 
    .LINK
        https://tlindsay42.github.io/PSRyver/Private/Format-RyverV1FileObject/
 
    .LINK
        https://github.com/tlindsay42/PSRyver/blob/master/PSRyver/Private/Format-RyverV1FileObject.ps1
 
    .FUNCTIONALITY
        Ryver
    #>

    [CmdletBinding(
        HelpUri = 'https://tlindsay42.github.io/PSRyver/Private/Format-RyverV1FileObject/'
    )]
    [OutputType( [PSCustomObject[]] )]
    [OutputType( [PSCustomObject] )]
    param (
        [Parameter(
            Mandatory = $true,
            Position = 0,
            ValueFromPipeline = $true
        )]
        $InputObject,

        [Parameter( Position = 1 )]
        [Switch]
        $Match = $false
    )

    begin {
        $function = $MyInvocation.MyCommand.Name

        Write-Verbose -Message (
            "Beginning: '${function}' with ParameterSetName '$( $PSCmdlet.ParameterSetName )' and Parameters: " +
            ( $PSBoundParameters | Remove-SensitiveData | Format-Table -AutoSize | Out-String )
        )
    }

    process {
        $files = $InputObject.files

        foreach ( $file in $files ) {
            $username = $null
            $map = @{}

            foreach ( $key in $Script:PSRyverUserMap.Keys ) {
                $map.Add( $Script:PSRyverUserMap[$key], $key )
            }

            if ( $map.ContainsKey( $file.User ) ) {
                $username = $map[$file.User]
            }

            if ( $Script:PSRyverUserMap.Keys.Count -like 0 ) {
                Write-Verbose -Message "No Ryver User Map found. Please run: 'Get-RyverUserMap -Update'"
            }

            [PSCustomObject]@{
                PSTypeName         = 'PSRyver.File'
                ID                 = $file.ID
                Name               = $file.Name
                Created            = ConvertFrom-UnixTime -UnixTime $file.Created
                Title              = $file.Title
                MimeType           = $file.MimeType
                FileType           = $file.FileType
                Type               = $file.Pretty_Type
                UserName           = $username
                UserID             = $file.User
                Size               = $file.Size
                IsPublic           = $file.Is_Public
                PermalinkPublic    = $file.Permalink_Public
                Permalink          = $file.Permalink
                UrlPrivateDownload = $file.Url_Private_Download
                Lines              = $file.Lines
                Channels           = $file.Channels
                Groups             = $file.Groups
                IMs                = $file.IMs
                Raw                = $file
            }
        }
    }

    end {
        Write-Verbose -Message "Ending: '${function}'."
    }
}