Write-AzBlobItem.ps1
|
Function Write-AzBlobItem { <# .SYNOPSIS Upload item to 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 modify. .PARAMETER Body Content to write. .PARAMETER AccessToken Access token for authenticating with Azure Table Storage. .EXAMPLE $Item = Write-AzBlobItem -StorageAccountName "<StorageAccountName>" -ContainerName <ContainerName> -Body "Test content" -AccessToken $Token.AccessToken .NOTES Author: Michal Gajda .LINK https://learn.microsoft.com/en-us/rest/api/storageservices/put-blob?tabs=microsoft-entra-id #> [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact="Low")] Param( [Parameter(Mandatory = $true)] [String]$StorageAccountName, [Parameter(Mandatory = $true)] [String]$ContainerName, [Parameter()] [String]$Item, [Parameter(Mandatory = $true)] [String]$Body, [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 { #Write data to item 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,"Write data to item $($Item) to container $ContainerName")) { $Response = Invoke-RestMethod -Uri $Uri -Headers $Headers -Method PUT -Body $Body -ResponseHeadersVariable ResponseHeaders } Return $Result } End{} } New-Alias -Name "Upload-AzBlobItem" Receive-AzBlobItem |