Get-AzBlob.ps1
|
Function Get-AzBlob { <# .SYNOPSIS Get conainers from Azure Storage Account. .PARAMETER StorageAccountName Name of the storage account containing the table. .PARAMETER AccessToken Access token for authenticating with Azure Storage. .EXAMPLE #Require RBAC app permissions on storage account: Storage Blob Data Reader or Storage Table Blob Contributor $Params = @{ Scope = @("https://storage.azure.com/.default") ClientId = $Connection.ApplicationId TenantId = $Connection.TenantId RedirectUri = "https://login.microsoftonline.com/common/oauth2/nativeclient" Certificate = $Certificate } $Token = Get-PSMSALToken @Params #Get single item from Azure Table $Item = Get-AzBlob -StorageAccountName "<StorageAccountName>" -AccessToken $Token.AccessToken .NOTES Author: Michal Gajda .LINK https://learn.microsoft.com/en-us/rest/api/storageservices/get-container-properties?tabs=microsoft-entra-id #> [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact="Low")] Param( [Parameter(Mandatory = $true)] [String]$StorageAccountName, [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-structured-body" = "XSM/1.0; properties=crc64" } } Process { #Get list of containers in Storage Account $Uri = "https://$($StorageAccountName).blob.core.windows.net/?comp=list" Write-Verbose $Uri Write-Verbose "Headers: $($Headers | Select-Object -exclude "Authorization" | Convertto-Json -Compress)" If ($PSCmdlet.ShouldProcess($StorageAccountName,"Get list of containers")) { $Response = Invoke-RestMethod -Uri $Uri -Headers $Headers -Method GET -ResponseHeadersVariable ResponseHeaders Write-Verbose "Item retrieved: $($Response.Count)" $Xml = [xml]$Response.Substring($Response.IndexOf('<')) $Result = $Xml.EnumerationResults.Containers.Container } Return $Result } End{} } |