Skip to content

Set-StorageBlobContent

Azure: Uploads a storage blob

param(
	[Parameter(Mandatory = $true)]
	[string]$Container,

	[Parameter(Mandatory = $true)]
	[string]$FilePath,

	[Parameter(Mandatory = $false)]
	[string]$BlobName,

	[Parameter(Mandatory = $true)]
	[string]$StorageAccountName
)

try {
	Import-Module Az.Storage -ErrorAction Stop
	$ctx = (Get-AzStorageAccount -ResourceGroupName "*" -Name $StorageAccountName -ErrorAction Stop).Context
	
	[hashtable]$cmdArgs = @{ 'Container' = $Container; 'File' = $FilePath; 'Context' = $ctx; 'Force' = $true; 'ErrorAction' = 'Stop' }
	if ($BlobName) { $cmdArgs.Add('Blob', $BlobName) }

	$blob = Set-AzStorageBlobContent @cmdArgs
	Write-Output $blob
} catch {
	Write-Error $_
	exit 1
}

The name of the destination storage container.

The local path to the file to upload.

The name for the blob in the container (optional).

The name of the storage account.

An interactive directory of PowerShell scripts.