Functions/Get-SlackFile.ps1

<#
.SYNOPSIS
    This function gets files from a Slack team.
.DESCRIPTION
    This function gets files from a Slack team.
#>

function Get-SlackFile {
    [CmdletBinding(PositionalBinding=$false)]
    [OutputType([PSObject])]
    param(
        # The authentication token for Slack
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [String]$token,

        # Select the stream where the files will be directed.
        [Parameter(Mandatory=$false)]
        [ValidateSet("Information", "Warning", "Error", "None")]
        [String]$outputStream = "Error"
    )

    # Prepare the API call parameters
    $invokeRestMethodParams = @{
        Uri     = "https://slack.com/api/files.list"
        Method  = "GET"
        Headers = @{
            "Content-Type" = "application/x-www-form-urlencoded"
            Authorization  = "Bearer $($token)"
        }
    }

    # Try to retrieve files
    Write-Information "Retrieving files in Slack."
    try {
        $response = Invoke-RestMethod @invokeRestMethodParams
    }
    catch {
        Write-OutputMessage "Exception occurred while retrieving files.`r`n$($_.Exception.Message)" -OutputStream $outputStream -ReturnMessage:$false
        return $null
    }

    # Verify that the retrieval is successful
    if ($response.ok) {
        return $response.files
    }
    else {
        Write-OutputMessage "Failed to get files with the error message:`r`n$($response.error)." -OutputStream $outputStream -ReturnMessage:$false
        return $null
    }
}