Receive-AzBlobItem.ps1
|
Function Receive-AzBlobItem { <# .SYNOPSIS Download item 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 Name of the item to query. .PARAMETER AccessToken Access token for authenticating with Azure Table Storage. .PARAMETER DestinationPath Path of destination location. .EXAMPLE $Item = Receive-AzBlobItem -StorageAccountName "<StorageAccountName>" -ContainerName <ContainerName> -Item <ItemName/ItemPath> -DestinationPath <DestinationPath> -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, [Parameter(Mandatory = $true)] $DestinationPath ) Begin { #Build headers $Date = [DateTime]::UtcNow.ToString('R') $Headers = @{ "x-ms-version" = "2026-06-06" "x-ms-date" = $Date "Authorization" = "Bearer $($AccessToken)" } } Process { #Get list of files in Storage Account container $Uri = "https://$($StorageAccountName).blob.core.windows.net/$($ContainerName)/$($Item)" $FileName = Split-Path $Uri -Leaf Write-Verbose $Uri Write-Verbose "Headers: $($Headers | Select-Object -exclude "Authorization" | Convertto-Json -Compress)" If ($PSCmdlet.ShouldProcess($StorageAccountName,"Download item $($Item) from container $ContainerName")) { Invoke-WebRequest -Uri $Uri -OutFile "$($DonloadPath)/$($FileName)" -Headers $Headers $Result = Get-Item -Path "$($DonloadPath)/$($FileName)" } Return $Result } End{} } New-Alias -Name "Download-AzBlobItem" Receive-AzBlobItem |