Skip to content

Instantly share code, notes, and snippets.

@poiriersimon
Created August 15, 2019 14:03
Show Gist options
  • Save poiriersimon/5223a975c0f40845ee4a781514f6e28a to your computer and use it in GitHub Desktop.
Save poiriersimon/5223a975c0f40845ee4a781514f6e28a to your computer and use it in GitHub Desktop.
Upload file to Azure Blog Container
$StorageAccountName = "Demostorage"
$ContainerName = "Democontainer"
$BlobDirectory = "BlobDir"
$localFilePath = "C:\Temp\"
$CredObj = Get-Credential "Enter Storage Account Key Only"
Import-Module AzureRM
$StorageAccountKey = $CredObj.GetNetworkCredential().Password
$ctx = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$localFileDirectory = Split-Path $localFilePath
$Filename = Split-Path $localFilePath -leaf
$localFile = $localFileDirectory + "\" + $Filename
$BlobName = $BlobDirectory + "\"+ $Filename
Try{
Set-AzureStorageBlobContent -File $localFile -Container $ContainerName -Blob $BlobName -Context $ctx -ErrorAction Stop
Remove-item $localFilePath -confirm:$false -force
}
Catch{
Throw "Can't upload"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment