Read-AzBlobItem.ps1

Function Get-AzBlobItem
{
    <#
    .SYNOPSIS
        Get items from Azure Storage Account container.
 
    .PARAMETER StorageAccountName
        Name of the storage account containing the table.
 
    .PARAMETER ContainerName
        Name of the container to query.
 
    .PARAMETER Item
        Item to read.
 
    .PARAMETER AccessToken
        Access token for authenticating with Azure Table Storage.
 
    .EXAMPLE
        $Item = Read-AzBlobItem -StorageAccountName "<StorageAccountName>" -ContainerName <ContainerName> -Item <Item> -AccessToken $Token.AccessToken
 
    .NOTES
        Author: Michal Gajda
 
    .LINK
        https://learn.microsoft.com/en-us/rest/api/storageservices/get-blob?tabs=microsoft-entra-id
#>


    [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact="Low")]
    Param(
        [Parameter(Mandatory = $true)]
        [String]$StorageAccountName,
        [Parameter(Mandatory = $true)]
        [String]$ContainerName,
        [Parameter(Mandatory = $true)]
        [String]$Item,
        [Parameter(Mandatory = $true)]
        [String]$AccessToken
    )

    Begin
    {
        #Build headers
        $Date = [DateTime]::UtcNow.ToString('R')
        $Headers = @{
            "x-ms-version"  = "2026-06-06"
            "x-ms-date"     = $Date
            "Authorization" = "Bearer $($AccessToken)"
            "x-ms-blob-type" = "BlockBlob"
        }
    }

    Process
    {
        #Get list of files in Storage Account container
        $Uri = "https://$($StorageAccountName).blob.core.windows.net/$($ContainerName)/$($Item)"

        Write-Verbose $Uri
        Write-Verbose "Headers: $($Headers | Select-Object -exclude "Authorization" | Convertto-Json -Compress)"

        If ($PSCmdlet.ShouldProcess($StorageAccountName,"Get item $Item in container $ContainerName"))
        {
            $Response = Invoke-RestMethod -Uri $Uri -Headers $Headers -Method GET -ResponseHeadersVariable ResponseHeaders
            Write-Verbose "Item retrieved: $($Response.Count)"
        }

        Return $Response
    }

    End{}
}