Public/Get-SpecBlobFileFromURL.ps1

function Get-SpecBlobFileFromURL {
    <#
    .SYNOPSIS
    Downloads a file from the specified URL and saves it to the specified local path.
 
    .DESCRIPTION
    The Get-SpecBLOBFileFromURL function downloads a file from the given URL and saves it to the specified local file path. It utilizes Invoke-RestMethod to download the file.
 
    .PARAMETER FileUrl
    Specifies the URL of the file to be downloaded.
 
    .PARAMETER DestinationFilePath
    Specifies the local path where the downloaded file will be saved. Include the filename in the path.
 
    .EXAMPLE
    Get-SpecBLOBFileFromURL -FileUrl "https://example.com/file.zip" -DestinationFilePath "C:\Downloads\file.zip"
    Downloads the file from the specified URL and saves it to the specified local path.
 
    .NOTES
    Author: owen.heaume
    Change Log:
        - 2.0.0 Uses invoke-restmethod
        - 2.0.1 Added error handling
                 Accepts object as input or via pipeline
                 Change parameter name for clarity
        - 2.0.2 Added alias for parameter
    #>

    [cmdletbinding()]
    param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [string]$FileUrl,
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
        [Alias("FilePath")]
        [string]$DestinationFilePath
    )

    begin {}

    process {
        foreach ($url in $FileUrl) {
            Try {
                # Download the file to $FileLocation
                Invoke-RestMethod -Uri $url -OutFile $DestinationFilePath -UseBasicParsing -ea stop -ev x
                Write-Host "File downloaded to $DestinationFilePath" -ForegroundColor DarkGray
            } Catch {
                [pscustomobject]@{
                    'FileUrl'      = $url.Split('?')[0]
                    'FilePath'     = $DestinationFilePath
                    'ErrorMessage' = $_.Exception.Message
                }
            }
        }
    }
}